Is it possible to stop tracking local changes to a file that you *do* want to be pulled down if changed in the repo?

时光毁灭记忆、已成空白 提交于 2019-12-01 09:36:18

The .gitignore file doesn't apply here because that stops new files from being added, but again, this file has already been added.
I just want it to always ignore my local changes.

Another approach would be to make your modifications... in a private file, one which is not tracked and is ignored.

Meaning all the common contributions are done in a template file., 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 aConfigFile aConfigFile.tpl
git commit -m "record template config file"

Then add to aConfigFile 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)


(image from "Customizing Git - Git Attributes", from "Pro Git book")

smudge script (which you can version): YourScript

copy aConfigFile.tpl aConfigFile

Declare the content filter driver in a versioned .gitattributes:

echo 'aConfigFile.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.

Any modification done on the generated file will remain local.

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