Try it (using SHA 1 and 5 , as in your example):
git diff 1 5 $(git diff --raw --no-commit-id --name-only -r 1~1 1)
Or more comfortable, so you only need to dial each SHA once:
c1="1"; c2="5" git diff $c1 $c2 $(git diff --raw --no-commit-id --name-only -r $c1~1 $c1)
How it works: The first git diff compares two commits. The second generates a list of paths to limit comparisons. This list is created by comparing files that were changed between your old commit $c1 and its parent $c1~1 . (This also works when specifying something like the tenth last commit using c1="HEAD~10" , since HEAD~10~1 is a valid tree in git, equivalent to HEAD~11 )
The subshell uses git diff --raw to work for commits. Otherwise, we could use git diff-tree --no-commit-id --name-only -r $c1 , which automatically compares the commit with its parent.
TODO: Not yet working. This works from time to time, sometimes I get a "fatal: ambiguous argument" <file_name> ': unknown revision or path not in the working tree. "
source share