Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git log graph, display how two branches are diverging

Tags:

git

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?

like image 804
Shaun Luttin Avatar asked Nov 06 '14 16:11

Shaun Luttin


People also ask

How can you tell if two branches are identical?

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.

Does git log show all branches?

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.

What does the command git log Oneline graph do?

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.

What happens when you merge two branches in Git?

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.

What does the--graph option to git log do?

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.

Is git log --graph in chronological order?

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.”

How to compare two branch heads in Git?

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.


1 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.

like image 189
chepner Avatar answered Oct 02 '22 06:10

chepner