I want a diff of all changes in a branch that is not merged to master yet.
I tried:
git diff master
git diff branch..master
git diff branch...master
However, in each of these cases the diff contains content in master that has not been merged into my branch yet.
Is there a way to do a diff between my branch and master that excludes changes in master that have not been merged into my branch yet?
Compare two branches using git diff In short, it will show you all the commits that “branch2” has that are not in “branch1”. Let's say for example that you are looking to see the differences between a feature branch (being one commit ahead of master) and the master branch.
To see the changes between two commits, you can use git diff ID1.. ID2 , where ID1 and ID2 identify the two commits you're interested in, and the connector .. is a pair of dots. For example, git diff abc123.. def456 shows the differences between the commits abc123 and def456 , while git diff HEAD~1..
git diff `git merge-base master branch`..branch
Merge base is the point where branch
diverged from master
.
Git diff supports a special syntax for this:
git diff master...branch
You must not swap the sides because then you would get the other branch. You want to know what changed in branch
since it diverged from master
, not the other way round.
You may want to replace branch
in this syntax with HEAD
or even delete it completely -- both the following display the content of the current branch since it diverged from master:
git diff master...HEAD
git diff master...
Loosely related:
Note that ..
and ...
syntax does not have the same semantics as in other Git tools. It differs from the meaning specified in man gitrevisions
.
Quoting man git-diff
:
git diff [--options] <commit> <commit> [--] [<path>…]
This is to view the changes between two arbitrary
<commit>
.
git diff [--options] <commit>..<commit> [--] [<path>…]
This is synonymous to the previous form. If
<commit>
on one side is omitted, it will have the same effect as usingHEAD
instead.
git diff [--options] <commit>...<commit> [--] [<path>…]
This form is to view the changes on the branch containing and up to the second
<commit>
, starting at a common ancestor of both<commit>
. "git diff A...B
" is equivalent to "git diff $(git-merge-base A B) B
". You can omit any one of<commit>
, which has the same effect as usingHEAD
instead.Just in case you are doing something exotic, it should be noted that all of the
<commit>
in the above description, except in the last two forms that use ".." notations, can be any<tree>
.For a more complete list of ways to spell
<commit>
, see "SPECIFYING REVISIONS" section ingitrevisions[7]
. However, "diff" is about comparing two endpoints, not ranges, and the range notations ("<commit>..<commit>
" and "<commit>...<commit>
") do not mean a range as defined in the "SPECIFYING RANGES" section ingitrevisions[7]
.
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