Git log graph, display how two branches are diverging

Git

Git Problem Overview


We would like to view a graph of how two branches are diverging. Running git log --oneline --graph displays only the current branch. How do we include both branches in the graph?

Git Solutions


Solution 1 - Git

git log takes zero or more commits as arguments, showing the history leading up to that commit. When no argument is given, HEAD is assumed. For your case, you want to supply the two branch heads you want to compare:

git log --graph --oneline currentbranch otherbranch

If it doesn't display too much, you can simplify this by using

git log --graph --oneline --all

which acts as if you had specified every reference in .git/refs as the commits to display.

Solution 2 - Git

I had the same issue and landed here, but no answer helped me to display how two branches are diverging. Eventually I did experiment myself and found this worked.

Given branch A and branch B, I want to see where they diverged.

git log --oneline --graph --decorate A B `git merge-base A B`^!

Note: Don't forget there is ^! at the end. (It excludes the parents of the commit returned by merge-base.)

UPDATE

The one line command above isn't working in case merge base is more than one. In this case do this:

git merge-base A B -a
# e.g. output XXXX YYYY
git log --oneline --graph --decorate A B --not XXXX^ YYYY^

Solution 3 - Git

git log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionShaun LuttinView Question on Stackoverflow
Solution 1 - GitchepnerView Answer on Stackoverflow
Solution 2 - Gitfikr4nView Answer on Stackoverflow
Solution 3 - GitKonrad SzałwińskiView Answer on Stackoverflow