开发者

How to make git quit tracking changes to a file while keeping it in the index?

I have a config file stuff.conf in an open source project I'm working on. I want an example copy of this file to live in the Git repository (in it开发者_如何学Pythons rightful path) so that people who clone the project will get it. However, it's convenient to make local changes to the config while working on the software---at which point I inevitably inadvertently commit those changes with git -a. At best, the changed file lies around whining at git status.

A similar problem arises in Makefiles with config variables in them.

Is there any way, short of removing the file from Git control, to tell Git to simply ignore changes to a particular path until further notice?


git update-index --assume-unchanged should do the trick.

From http://www.kernel.org/pub/software/scm/git/docs/git-update-index.html:

When the "assume unchanged" bit is on, git stops checking the working tree files for possible modifications, so you need to manually unset the bit to tell git when you change the working tree file. This is sometimes helpful when working with a big project on a filesystem that has very slow lstat(2) system call (e.g. cifs).

This option can be also used as a coarse file-level mechanism to ignore uncommitted changes in tracked files (akin to what .gitignore does for untracked files). Git will fail (gracefully) in case it needs to modify this file in the index e.g. when merging in a commit; thus, in case the assumed-untracked file is changed upstream, you will need to handle the situation manually.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜