git - 跟踪忽略和 --assume-unchanged 如何进行 merge

标签 git

在我的 Git 存储库中,有一个配置文件,我希望将其与主共享存储库不同(它必须保持跟踪),以便更改不会填充到其他开发人员中。然而,“--assume-unchanged”可以很好地在本地保存我的更改,同时将代码推送到其他存储库。问题就变成了,当我需要获取最新的代码并且我从共享存储库 pull 或 merge 到我的本地时,我会收到错误:

error: Your local changes to the following files would be overwritten by merge:
    app/grails-app/conf/BuildConfig.groovy
Please, commit your changes or stash them before you can merge.
Aborting

该错误是有道理的,因为我的配置文件与我要 merge 的共享存储库中的配置文件不同。但是我如何获取( merge )最新代码,同时保持此配置不同。我想避免解决方法:

git update-index --no-assume-unchanged app/grails-app/conf/BuildConfig.groovy
git stash save "config file"

然后在 merge 后取回我更改的配置:

git stash apply

如何避免这些额外的存储和索引步骤 - 假设不变?有没有办法提取除一个文件之外的所有内容?对于所描述的问题还有其他解决方案吗?

谢谢

最佳答案

据我了解,您想在本地忽略文件(意味着其他开发人员仍会跟踪该文件),因此 .gitignore 对您没有帮助,因为它的影响是全局的。

但是,如果您将文件添加到.git/info/exclude,它将在本地被忽略。

这句话来自.gitignore :

Patterns which are specific to a particular repository but which do not need to be shared with other related repositories (e.g., auxiliary files that live inside the repository but are specific to one user's workflow) should go into the $GIT_DIR/info/exclude file

关于git - 跟踪忽略和 --assume-unchanged 如何进行 merge ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15072513/

相关文章:

git - 术语混淆, "theirs"与 "mine"

java - 查找 2 个 git 提交之间可用的分支

.net - Git在windows中更改 '.git'文件夹名称

git - JIRA 智能提交的精确格式

git - 如何防止 git 更改文件所有权

git - 推送标签时如何触发VSTS构建和发布?

java - 犹豫不决要在 GitHub 上上传哪些文件

android - TeamCity:配置多个构建任务以使用相同的 VCS 下载

git - 如何使 CVS 和 git 存储库保持同步?什么脚本可以帮助我管理它?

git 如何移回提交