Git Diff 2 Different Commits, Tags or Branches
Compare what changed between 2 points in time to help identify errors in production or evaluate changelogs.
git diff <commit> <commit>
git diff <tag> <tag>
git diff <branch> <branch>
You can also mix and match reference types. For example you might want to see
what changed between the most recent tag and the latest commit with git diff <tag> HEAD
.
GitHub, GitLab and Bitbucket all have UIs to view these types of comparisons
too. For example, here’s a diff between the latest 3 commits on
GitHub
for one of my projects which uses HEAD~3
. I use this to show what changed
between tagged releases in my changelog
files.
# Demo Video
Timestamps
- 0:19 – One use case for this
- 0:36 – Diffing 2 commits
- 1:19 – Diffing 2 tags
- 1:56 – Diffing 2 branches
- 2:24 – Combining reference types
- 3:07 – Comparing references on GitHub
- 4:39 – Creating changelog links
How often do you diff things in git? Let us know below!