With git diff, you can check the difference between two branches. Let’s see it in action in the demo below.
The current branch is main with the history shown below.
$ git status
On branch main
nothing to commit, working tree clean
$ git log --oneline
bfdb0a5 add version 3
c3f49dc modify notes and add version
1d96512 add notes and metadata
Created a new branch named feature1. While in the new branch, contents of notes were changed, and a commit was made.
$ git switch -c feature1
Switched to a new branch 'feature1'
$ cat notes
version 3
$ echo "version 4" > notes
$ git status
On branch feature1
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: notes
no changes added to commit (use "git add" and/or "git commit -a")
$ git add notes
$ git commit -m "update notes with v4"
[feature1 f58940f] update notes with v4
1 file changed, 1 insertion(+), 1 deletion(-)
With git diff, we can see that the full difference between the two branches. The output shows the affected files and the content difference.
$ git diff main..feature1
diff --git a/notes b/notes
index 7170a52..96ac8f8 100644
--- a/notes
+++ b/notes
@@ -1 +1 @@
-version 3
+version 4
--name-only is to only show the names of the files that have differences.
$ git diff --name-only main..feature1
notes
On the other hand, --stat is used here to show the summary.
$ git diff --stat main..feature1
notes | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)