There is a file that should be in our git repository so that it is in any checkout. It may be changed by users, but usually the changes should not be checked back in. Neither --assume_unchanged nor --skip_work_tree provide the required flexibility, and the file is too cumbersome to reasonably be 'modified' with smudge/clean filters.
So I've written a pre-commit hook that successfully asks the user if they're sure they want to commit the changes to this file. If they say yes, the file is checked in (hook returns 0, commit continues), if not, the commit is aborted.
Instead of aborting, I'd like to give the user the option to revert changes to the file and continue with the commit.
To revert the file to an unchanged state, I'm using git checkout -- file/in/question
.
Given that the file is modified and staged for commit, I run the following pre-commit hook:
#!/bin/bash
echo "git checkout -- file/in/question"
git checkout -- file/in/question
echo "git status"
git status
exit 1 #would be 0 if the hook worked as expected
And I get the following output:
git checkout -- file/in/question
git status
On branch blah
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: file/in/question
Why does git status report that the git checkout has had no effect? (it's correct - returning 0 from the hook causes the file to be incorrectly committed)