简体   繁体   English

如何在 Git 中停止跟踪文件但允许在本地副本上对其进行“可忽略的”更改?

[英]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.我需要在我的存储库中有一个文件,其他开发人员可以在他们的本地副本上修改该文件,同时让 Git 忽略这些更改。

Can't use git rm --cached <file> because the file is removed from the remote, making the file unavailable for future clones/pulls.无法使用git rm --cached <file>因为该文件已从远程删除,使该文件无法用于将来的克隆/拉取。

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:不能使用git update-index --assume-unchanged <file>git update-index --skip-worktree <file>因为从技术上讲该文件仍在跟踪中,因为 git 在任何工作树覆盖操作上吐出此错误消息(例如git checkoutgit merge )如果开发人员修改了文件:

"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.无法将文件添加到.gitignore因为它已被跟踪。

Is there any Git operation I can use to achieve this?我可以使用任何 Git 操作来实现这一目标吗?

Thanks.谢谢。

There is no way to allow ignoreable changes to the file in the local copy.无法允许对本地副本中的文件进行可忽略的更改。 The Git FAQ explains this thoroughly. Git FAQ彻底解释了这一点。

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.将其命名为不同的名称,然后使用脚本将其复制到位或让用户将其复制到正确的位置,并在跟踪模板时忽略实际的配置文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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