When you are working with multiple branches in Git, itβs important to be able to compare them and contrast the differences.
In this short note i will show how to compare two branches in Git using the git diff
command.
I will show how to git diff
between any two branches, e.g. current branch and master or git diff
between master and staging and how to list only files that are different between two branches (without changes themselves).
Cool Tip: How to git diff
staged and unstaged files! Read more β
Git – Diff Between Branches
Diff between current branch and master:
$ git diff master
Diff between two branches, e.g. master and staging:
$ git diff master..staging
Show only files that are different between the two branches (without changes themselves):
$ git diff --name-status master..staging
Just a quick note – the diff will not work if you put a “..” between the names of the branches; should just be a space.
Somehow it worked for me with the “..” π
Worked for me too, just now. Got new branch from collaborator with no apparent changes (?), ran command with both space and .. delimiters. Both worked and confirmed that branch creator had made zero changes in that branch.
Nothing happens when I run it any of the following ways:
git diff myNonCurrentBranch
git diff myBranch1 myBranch2
git diff myBranch1..myBranch2
git diff origin/myBranch1 origin/myBranch2
git diff origin/myBranch1..origin/myBranch2
If it doesn’t work, try to use the complete name of the branch, the same you see when launching git branch -a
To show only files that are different between the two branches (without changes themselves):
git diff develop..master –name-status
Should be
git diff develop..master –name-status
in the above comment
When I press ‘Post’, the editor is converting my minus minus before name-status into a long hyphen!