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?
In order to compare two branches easily, you have to use the “git diff” command and provide the branch names separated by dots. Using this command, Git will compare the tip of both branches (also called the HEAD) and display a “diff” recap that you can use to see modifications.
Graph all git branchesDevelopers can see all branches in the graph with the –all switch. Also, in most situations, the –decorate switch will provide all the supplemental information in a formatted and nicely color-coded way.
git log by default shows the entire ancestry in order by birthdate (where timestamp weirdities don't make that contradict ancestry). Try it with git log --oneline --graph --decorate --first-parent . ^ or ^1 means the first parent.
The moral of this story is to avoid time travel whenever possible.) When you merge two branches, you’re creating a “merge” commit with two parents: the last commit of the branch you’re on, and the last commit of the branch you’re merging in.
Adding the --graph option to git log causes the construction of a commit tree with the help of simple ASCII characters. We see both branches (style and master) and that the current branch is master HEAD. The Added index.html branch goes prior to both branches. The --all flag guarantees that we see all the branches.
Note that git log --graph does not show the commits in chronological order. The git help man pages call it --topo-order, topological ordering. “Show no parents before all of its children are shown, and avoid showing commits on multiple lines of history intermixed.”
For your case, you want to supply the two branch heads you want to compare: If it doesn't display too much, you can simplify this by using which acts as if you had specified every reference in .git/refs as the commits to display. Both of these commands show the entire history.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With