38

If I have n git branches, how do I easily show the relationship between these branches?

Basically I am interested in seeing a tree of a subset of all the branches in my repository. I am however not interested in all the intermediate commits.

E.g.: My repository looks like this:

     o---o--o A
    /      /
o--o--o--o--o--o B
 \  \        \
  \  o--o C   \
   \     \     \
    o--o--o--o--o--o D

But probably way more complicated. Now I want to see the relationship between branch A, C and D. Something along the lines of:

     o A
    /
o--o--o
   \   \
    o---o C
         \
          o--o D

Or an equivalent overview. Is this possible, and how? (A graphical tool will be just fine.)

Solution

Based on Antoine Pelisses answer, the below line seems to do (almost) exactly what I want:

git log --graph --decorate --oneline --simplify-by-decoration A B C

Update

Mark Longair points out in his answer below that gitk accepts the same parameters as git rev-list, so it is possible to do:

gitk --simplify-by-decoration A C D
Bjarke Freund-Hansen
  • 28,728
  • 25
  • 92
  • 135

2 Answers2

51

You can give this a try:

git log --graph --all --decorate --simplify-by-decoration

It will only show commits that are branch heads or tagged.

Antoine Pelisse
  • 12,871
  • 4
  • 34
  • 34
20

I would use:

gitk A C D

... there are probably other git GUIs that produce a prettier rendering of the commit graph, but I've always found gitk fine for this purpose. All the branches and tags are labelled in the "London Underground"-style representation:

A screenshot of gitk showing several merges and branches
(source: mark at mythic-beasts.com)


You can also use the --simplify-by-decoration option to gitk, since it understands all of the parameters that git rev-list does, for example:

gitk --simplify-by-decoration A C D

A screenshot of gitk with the --simplify-by-decoration option

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Mark Longair
  • 446,582
  • 72
  • 411
  • 327
  • I also use gitk (and gitg) a lot. However, I have a case where I have around 5 branches, which each has several hundreds commits on them, and somewhere in between there are merges between these branches. Getting a overview of the merge history is very hard with gitk (or gitg). – Bjarke Freund-Hansen Mar 14 '11 at 13:31
  • 2
    Right. I think if it's a case that's that complicated, I would probably just care about whether a particular branch has already been merge into another one and use command-line tools to explore that. I think someone might have deleted a comment on your question that suggested using `git branch --contains C` for this purpose, which is indeed very helpful - it shows you all the branches that include the tip of the branch C (and so contain the complete history of branch C). – Mark Longair Mar 14 '11 at 13:38
  • 2
    @bjarkef: just as an additional note, I should have pointed out that you can use the --simplify-by-decoration option with gitk as well - I've updated my answer with a mention of that. – Mark Longair Mar 19 '11 at 08:52
  • That looks very useful, I will be sure to give it a try Monday. Thanks. – Bjarke Freund-Hansen Mar 19 '11 at 12:57