简体   繁体   中英

How to stop tracking file in Git BUT allow “ignorable” changes to it on local copy?

I need to have a file on my repository that other developers can modify on their local copy while having Git ignore those changes.

Can't use git rm --cached <file> because the file is removed from the remote, making the file unavailable for future clones/pulls.

Can't use git update-index --assume-unchanged <file> nor git update-index --skip-worktree <file> because technically the file is still being tracked since git spits out this error message on any work tree overriding operations (eg git checkout or git merge ) if the developer modifies the file:

"Please commit your changes or stash them before you switch branches. Aborting"

Can't add the file to .gitignore because it has been tracked already.

Is there any Git operation I can use to achieve this?

Thanks.

There is no way to allow ignoreable changes to the file in the local copy. The Git FAQ explains this thoroughly.

If you want to use a template file, don't name it the same thing as the file you want it to end up as. Name it something different, then either copy it into place with a script or let the user copy it into the right place, and ignore the actual configuration file while tracking the template.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM