Reputation: 23281
I'm curious if there is a way to show branch hierarchy on the command line? For instance if I use git branch
, instead of seeing output like this:
* master
joes_work
refactoring
experiment
You see output like this:
* master
joes_work
refactoring
experiment
That way it's easy to see which branch a particular branch.. branched off of. Even if there's no specific command that outputs a tree structure, is there a command that outputs information on which branch came from which branch? I can use a perl script to format the output.
Upvotes: 97
Views: 103597
Reputation: 781
I want to complete the answer of @ctcherry.
I like when I can also see the user who did the commit and the date, so this is the following line to use :
git log --all --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
However this is a pretty long line and difficult to memorize so you can use an alias. You just have to use this in your terminal :
git config --global alias.lg "HERE GOES MY BIG LOG COMMAND LINE"
To summarize copy and paste the line below on your terminal:
git config --global alias.lg "log --all --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
Then you will just have to use git lg
to get your log history tree.
Upvotes: 37
Reputation: 6488
Just type gitk
command and press enter.
For me gitk
is the easiest solution for this. Though it will not show you command mode, it will automatically populate a nice UI like this :
Upvotes: 18
Reputation: 393507
Try
git show-branch
git show-branch --all
Example output:
bash$ git show-branch --all
! [branchA] commitA only in branchA
* [branchB] commitB
! [branchC] commitC only in branchC
---------------------
+ [branchA] commitA only in branchA
* [branchB] commitB
+ [branchC] commitC only in branchC
*+ [branchC~1] commitB-1 also in branchC
*+ [branchC~2] commitB-2 also in branchC
+++ [branchC~3] common ancestor
+++ [branchC~4] more common ancestors
Upvotes: 34
Reputation: 36739
How about this alias for your .gitconfig
:
[alias]
branch-tree = !cd "$(git rev-parse --git-dir)/refs/heads" && tree
You can also give options, depending on what your tree
command supports, such as -D
for timestamps.
Upvotes: -3
Reputation: 28574
sehe's solution looks great, here is another one that seems to contain similar information, formatted differently, it uses git log, so it contains commit information as well (ignore the branch names, I kind of messed them up!):
git log --all --graph --decorate --oneline --simplify-by-decoration
* ae038ad (HEAD, branch2-1) add content to tmp1
| * f5a0029 (branch2-1-1) Add another
|/
* 3e56666 (branch1) Second wave of commits
| * 6c9af2a (branch1-2) add thing
|/
* bfcf30a (master) commit 1
Upvotes: 139
Reputation: 244928
That's not how branches work from git's point of view. If I make some commits to branch a
, create branch b
from it, work there, and then do other work back on a
:
A -- B -- D <-- a
\
\
C <-- b
That's indistinguishable if you did it the other way around:
A -- B -- C <-- b
\
\
D <-- a
The only way I can think of to find out from which branch certain branch originated is the reflog, but that's unreliable (entries older than 90 days are usually deleted).
Upvotes: 5