We want to compare the current branch and another branch to find the changes since they diverged.
For example, we create a new branch dev from branch master and add a few commits, the branch master also update after diverging.

The common ancestor is in the following part.

The following image shows the recent commit history, contains commits Add fun1 and Change fun1, on the dev branch.
As the description of the above git workflow image, I just changed the interface func1.

The content of commit Add fun2 on the master branch is just like

If we use git to diff the content of the dev branch with master branch, it will give us the following result.
It indicates the difference between the last status on the dev branch and master branch’s.

If we don’t know the change on the master branch after dev branch diverges from it, the result will seem misleading.
In most cases, we just want to know the difference between the last commit on the dev branch and common ancestor of both branches. How to do it in the above situation?
The solution is not complex, we just need to find the common ancestor between both branches, and compare the last content on the dev branch and the ancestor.

$ git merge-base dev master
$ git diff d313ed49d4981f11b52109d83a80c1edd5eb8733

Git provides a shorthand for doing the same thing: the triple-dot syntax.
We can put three periods after the other branch to do diff between the last commit of the branch where you are on and the common ancestor with the other branch.
$ git diff master...dev

We can get the same result by the syntax.

Categories: Tool

1 Comment

Git Rebase And Git Merge – theArcticOcean · 2019年7月29日 at pm9:39

[…] git rebase [<upstream> [<branch>]] git wiil go to another branch <branch> by command git checkout firstly and then apply the commits on it to <upstream> area. We wiil start with the example showed in the last article Git Diff Different Branches […]

Leave a Reply

Your email address will not be published. Required fields are marked *

You cannot copy content of this page