0

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.

Chris Maes
  • 35,025
  • 12
  • 111
  • 136
  • `git diff --name-only HEAD HEAD~4 -- filename` either report changes in the `filename` or doesn't. Why do you need `grep`? – phd Jul 30 '19 at 09:35
  • I want the return code to reflect whether there are changes or not. – Chris Maes Jul 30 '19 at 09:37

1 Answers1

1

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 
Corentin Limier
  • 4,946
  • 1
  • 13
  • 24