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?
3 Answers
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.
-
3Both of these commands show the entire history. Is there a way to graph only the changes on each branch since the branch point?– JohnMar 30, 2016 at 22:34
-
5@John I think you want
git log --graph --oneline current branch...otherbranch
, which shows all commits reachable from one of the two branch heads, but not from both.– chepnerMar 30, 2016 at 23:40 -
6With that command, the branch structure doesn't appear in the output. Instead the commits appear as a flat list, as if
--graph
wasn't used.– JohnMar 31, 2016 at 0:26 -
Nice alias:
cmp = log --graph --online HEAD
to usegit cmp OTHERSHA
Jan 2, 2019 at 20:57
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^
-
6This should be the preferred solution. Exactly what I was looking for.– Jay WestDec 8, 2018 at 3:37
-
If anybody wants an alias, here you go. Tested on Bash 5.0.18 macOS Mojave diverge = "!f() { if [[ $# -lt 1 ]] || [[ $# -gt 2 ]]; then >&2 echo \"Usage: git diverge BRANCH1 [BRANCH2]\"; return 1; fi; branch1=\"$1\"; branch2=\"${2:-HEAD}\"; base=\"$(git merge-base \"$branch1\" \"$branch2\")\" && git lg1-specific \"$branch1\" \"$branch2\" \"$base\"^!; }; f" Mar 22, 2021 at 16:09
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
-
3Two requests. 1. Could you please provide a simplified version that answers the question without providing extra functionality. 2. Could you explain how to only show the two branches rather than all branches. Nov 6, 2014 at 16:35