Skip to content
How to Compare Git Diffs Across Multiple Commits in Git
Dispatch

How to Compare Git Diffs Across Multiple Commits in Git

Learn how to diff changes across multiple commits in Git and Azure DevOps. Compare file changes over time with these practical diffing techniques and examples.

Go back

Cover image by Ross Findon (@rossf) on unsplash

A while back one of my colleagues was investigating an issue on a project he had just re-joined. There had been a lot of work done on various facets of the codebase (from memory there were React and Xamarin front ends and a .NET Core API).

The Problem

He wanted to see all the changes from when he last worked on the Xamarin project while he was away, if we unpack and abstract it, he wanted:

The Potential Solutions

  1. Bad choice - Go to the File view for the repo in Azure DevOps and see the list of commits In Azure DevOps you can see the history of commits for a specific folder This lists the specific commits that have changed files under the path but not the actual changes which is what he needed (he’d need to click on each commit, find the file(s) and look at the changes -> very time consuming)

  2. Unknown choice - I’m sure there’s a nice GUI that could do this with a click-click-done, but he didn’t have one already so this wasn’t a feasible option

  3. Good choice - Grab the SHA of the last commit he worked on and run a quick git command - here’s an example for the repo that creates this site

    git diff 741d760 df32e83b -- gatsby-*.js 

    If we break this command down, it looks like: sh•git diff <start commitish> <end commitish> -- <folder/file filter> (the — is there to separate the commits and the path) This will produce a diff with all the interim changes squashed down

After he ran this command, he was able to scroll through and see what had changed on the project - which helped him track down the issue (and when it was introduced).

The advantage of the terminal approach was that:

Disavantages? Yes, there are some:

I’d love to know how you go about solving this type of problem, or what tools you use to help with your git workflow. If you’re looking to level up your Git practices, check out my posts on signing your commits with GPG for verified authenticity and managing repository settings as code for better branch protection.

Edit page
Share this post on:
Discussion
Continue Reading
Previous
GitHub Repository Settings as Code: Automate Branch Protection
Next
How to Sign and Verify Your GitHub Commits with GPG Keys