I have created a default version of a file included in a git repository. It\'s important that when someone clones the repository, they get a copy of this file. However, I
I've solved this by defining the "clean" filter to simply cat the contents of the file in the index.
git show :path/to/myfile should just print the contents of the index for the specified file, so we can use that in a script to replace the working copy with the untouched copy in the index:
#! /bin/sh
git show :$1
Set that as the "clean" filter for the file concerned (assuming you've put that in "discard_changes"):
$ git config filter.ignore_myfile.clean "discard_changes path/to/myfile"
$ echo "path/to/myfile filter=ignore_myfile" >> .gitattributes
Unfortunately I can't find a way to make this generalisable to multiple files, as there's no way to tell which file we're processing from inside the clean script. Of course, there's nothing to stop you from adding a different filter rule for each file, but it's a bit cludgy.