gitgit-diffgit-plumbing

git (plumbing) has a file changed between two commits?


Is there a git (preferably plumbing) command to check if a file has changed between two commits?

I can check this with a little grep but this does not feel like the cleanest solution:

git diff --name-only HEAD HEAD~4 -- filename | grep -q filename

EDIT : I want the return code to reflect whether the file has changed or not.


Solution

  • Documentation says that you can use --exit-code option

    --exit-code Make the program exit with codes similar to diff(1). That is, it exits with 1 if there were differences and 0 means no differences.

    git diff --exit-code HEAD HEAD~4 -- filename