Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Relationship between n git branches

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 
like image 630
Bjarke Freund-Hansen Avatar asked Mar 14 '11 13:03

Bjarke Freund-Hansen


People also ask

How do I compare two Github branches?

On the Github, go to the Source view of your project. You will see a link named 'Branch List'. Once the page opens you can see a list of all the remote branches. Hit on the Compare button in front of any of the available branches to see the difference between two branches.

What is the difference between git branch and git branch?

git branch creates the branch but you remain in the current branch that you have checked out. git checkout -b creates a branch and checks it out. Let's rather say: "git branch creates the branch but you remain in the current branch FROM WHICH you have checked out."

What are the branches of git?

In Git, branches are a part of your everyday development process. Git branches are effectively a pointer to a snapshot of your changes. When you want to add a new feature or fix a bug—no matter how big or how small—you spawn a new branch to encapsulate your changes.

What are the three types of branching in git?

The two primary branches in Git flow are main and develop. There are three types of supporting branches with different intended purposes: feature, release, and hotfix.


2 Answers

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.

like image 170
Antoine Pelisse Avatar answered Sep 17 '22 22:09

Antoine Pelisse


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

like image 40
Mark Longair Avatar answered Sep 19 '22 22:09

Mark Longair