Git ignore changes to committed file

心已入冬 提交于 2019-12-05 10:15:04

I have a config file in my repo that shouldn't get changes committed to it.

Then... don't commit that file in the first place.
Commit a generic version of that file, a template used to generate the actual file (as a private non-versioned file, added to your .gitignore).

That generation would be automatic on git checkout.

First, rename your existing file:

git mv afileToIgnore afile.tpl
git commit -m "record template value file"

Then add to afileToIgnore to a .gitignore file: a git status won't show it anymore to be added/changed.

Now, declare a smudge content filter driver which, automatically, will re-generate that file (ignored, since it is in .gitignore)

smudge script (which you can version): YourScript

copy aFileToIgnore.tpl aFileToIgnore

Declare the content filter driver in a versioned .gitattributes:

echo 'aFileToIgnore.tpl config' >> .gitattributes

That smudge 'config' content filter driver needs to be activated locally by each user cloning that repo.

cd /path/to/repo
git config filter.config.smudge YourScript

That last step is the only one each user need to do in order to benefit from the actual config file to be automatically generated on each git checkout.


Others who clone need to apply the same command.

True, but here, if they don't, they won't have the config file at all.
That is more visible than having the file ready to be modified when it should not be.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!