Last Updated: September 22, 2018
·
1.818K
· carleeto

Find files that have changed between two commits

I use a git alias to check which files have changed between two revisions:

git config --global alias.chgd 'diff --name-only'

Now, given any two commits, git chgd commit1 commit2 will list the changed files between them. This also works for branches: git chgd master my_branch

Ofcourse, you don't have to name it chgd. Use whatever else you like as long as it doesn't conflict with an existing command.

6 Responses
Add your response

Thanks bro this is handy.

here are a couple for you as well, hopefully they are helpful.

  • Show modified files in the last commit (most recent).

note: you have to put them in your git config like they are below.

dl = "!git ll -1"
  • show diff of the most recent commit
dl = "!git ll -1"
  • and, Show full diff of a commit given a revision (commit sha)
dr  = "!f() { git diff "$1"^.."$1"; }; f"

example usage of dr

$ g dr c4965e2  

use whatever commit sha or (treeish in git) you want to compare the current commit against.

the above are from this super post about git aliases

Thanks for your tip bro! I hope mine was of use as well.

I will post all my aliases in a couple of days.

over 1 year ago ·

I hadn't seen --name-only. I tend to use this a lot instead (which also tells you how many lines were added/removed from each file):

git diff --stat HEAD^
over 1 year ago ·

What's the difference to 'git status'?

over 1 year ago ·

You can't pipe the output of git status to a script that expects a list of files to operate on,

over 1 year ago ·

@jwebcat Thanks for that awesome page. I used yours and a few from there too.

over 1 year ago ·

@carleeto of course :D I'm glad you enjoyed bro. I am going to do a mega git alias protip soon with all of my aliases.

over 1 year ago ·