How can I make git ignore future revisions to a file?

前端 未结 7 1869
盖世英雄少女心
盖世英雄少女心 2020-11-28 18:31

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

7条回答
  •  借酒劲吻你
    2020-11-28 18:56

    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.

提交回复
热议问题