tags:

views:

105

answers:

2

A riff on git: show all changed files between two commits: I want a listing of all files that have been changed between two commits, even if they are now the same (ie, changed and then changed back).

+1  A: 

This is the best I could come up with:

git log --name-only --pretty=oneline --full-index HEAD^^..HEAD | grep -vE '^[0-9a-f]{40} ' | sort | uniq

Replace HEAD^^ and HEAD with the commits you want to compare.

My attempt uses git log with --name-only to list all files of each commit between the specified ones. --pretty=oneline makes the part above the file listing consist only of the commit SHA and message title. --full-index makes the SHA be the full 40 characters. grep filters out anything looking like a SHA followed by a space. Unless you have files beginning with a SHA followed by a space, the result should be accurate.

igorw
When I run that command against HEAD^ and HEAD, I get a list of what looks like every single file in the repository; even those that haven't changed.
Blair Holloway
My bad, the format is "<commit1>..<commit2>" instead of "<commit1> <commit2>".
igorw
Thanks, a little awkward but it will do.
Andrew
+1  A: 

I think this command is your answer:

git diff --stat abc123 xyz123  #where abc123 and xyz123 are SHA1 hashes of commit objects

Straight from the git community book

If you don't want to see the whole patch, you can add the '--stat' option, which will limit the output to the files that have changed along with a little text graph depicting how many lines changed in each file.

Bryce
More specifically, `git diff --stat <commit1> <commit2>`.
Blair Holloway
No, this is exactly not what he wanted. Git diff does a direct diff between the trees, it does not consider the commits. If you create a new file with contents "A", then change the contents to "B", then change them back to "A", `git diff --stat HEAD^^ HEAD` will give you a blank output.
igorw