How to check the difference between branches (Git)

Reginald LynchOctober 30th 2020, 9:18

A regular git diff between two branches will show you all the information, but it can be rather exhausting to sit and look at; maybe you are only interested in one file. Thus, you don't need the long unified diff.

Perform the following steps to see the difference between the branches:

Step 1 : Diff origin/stable-3.1 with the origin/stable-3.2 branch:

#git diff [options] <commit> <commit> <path></path>
git diff --name-only origin/stable-3.1 origin/stable-3.2 org.eclipse.jgit/src/org/eclipse/jgit/transport/

Step 2 : Let's try the same diff between branches, but this time we will diff the entire branches, not just a sub-directory; however, we only want to show the deleted or added files between the branches. This is done by using the --diff-filter=DA and --name-status options. The --name-status option will only show the filenames and the type of change. The --diff-filter=DA option will only show the deleted and added files:

git diff --name-status --diff-filter=DA origin/stable-3.1 origin/stable-3.2

This shows the files that have been added and deleted while moving from origin/stable-3.1 to origin/stable-3.2.

Step 3 : If we switch the branches around, as in the following command, we will get the opposite result:

git diff --name-status --diff-filter=DA origin/stable-3.2 origin/stable-3.1