git update-index --assume-unchanged 后合并的问题
Problems with merging after a git update-index --assume-unchanged
我的同事问我他是否可以在提交文件后删除文件,例如 pom.xml 文件,通常在 maven 项目中使用。
我发现 git update-index --assume-unchanged 在这种情况下很有用。但是当我尝试从另一个分支合并时,git 仍在跟踪被忽略的文件并且发生了冲突。
我应该怎么做才能避免这种情况?我应该在所有分支中使用这个命令(git update-index assume-unchanged)吗?
正如我评论的那样 - --assume-unchanged
isn't the right tool for this job
According to the Git documentation 最好的方法是使用 git rm --cached <file>
;
Another useful thing you may want to do is to keep the file in your working tree but remove it from your staging area. In other words, you may want to keep the file on your hard drive but not have Git track it anymore. This is particularly useful if you forgot to add something to your .gitignore file and accidentally staged it, like a large log file or a bunch of .a compiled files. To do this, use the --cached
option
然后您需要将现在未跟踪的文件添加到您的 .gitignore
文件中。
对于分支 - 您将必须管理跟踪此文件的分支的合并,以确保它不会再次进入存储库。最简单的方法是在合并之前在每个分支中进行此更改。
I found out the git update-index --assume-unchanged
这告诉 git 不要将工作目录中的文件与当前存储库状态进行比较。
另一方面,合并发生在存储库中的提交之间。因此,如果您与其他人对同一文件所做的更改合并,您仍然会遇到冲突。
您需要该功能的示例是 Mavens 项目配置文件。
我觉得尤其是这个文件不应该被忽略或以其他方式从 scm 中排除。那你为什么需要那个?
我的猜测是您在 pom 中定义了指向本地资源的属性。如果是这样:将该属性移动到 "user.home"/.m2
中的 settings.xml
。这是他们的归宿。
命令git update-index --assume-unchanged filename
不能在两个分支中使用,这是一种暂时忽略文件的方法。当你修改文件,然后想切换或合并到其他分支时,git 会为你显示错误信息,因为你有 un-commit 个更改,这意味着你应该在切换前使用 git update-index --no-assume-unchanged filename
或合并分支。
针对你的情况,可以参考以下两种方式:
- 该文件不再需要做版本控制。所以你可以在
.gitignore
中添加文件,然后使用 git rm --cached filename
取消跟踪它。
- 需要对文件做版本控制。合并分支时,可以使用
git merge branchname -X ours/theirs
使文件无效。
我的同事问我他是否可以在提交文件后删除文件,例如 pom.xml 文件,通常在 maven 项目中使用。
我发现 git update-index --assume-unchanged 在这种情况下很有用。但是当我尝试从另一个分支合并时,git 仍在跟踪被忽略的文件并且发生了冲突。
我应该怎么做才能避免这种情况?我应该在所有分支中使用这个命令(git update-index assume-unchanged)吗?
正如我评论的那样 - --assume-unchanged
isn't the right tool for this job
According to the Git documentation 最好的方法是使用 git rm --cached <file>
;
Another useful thing you may want to do is to keep the file in your working tree but remove it from your staging area. In other words, you may want to keep the file on your hard drive but not have Git track it anymore. This is particularly useful if you forgot to add something to your .gitignore file and accidentally staged it, like a large log file or a bunch of .a compiled files. To do this, use the
--cached
option
然后您需要将现在未跟踪的文件添加到您的 .gitignore
文件中。
对于分支 - 您将必须管理跟踪此文件的分支的合并,以确保它不会再次进入存储库。最简单的方法是在合并之前在每个分支中进行此更改。
I found out the git update-index --assume-unchanged
这告诉 git 不要将工作目录中的文件与当前存储库状态进行比较。
另一方面,合并发生在存储库中的提交之间。因此,如果您与其他人对同一文件所做的更改合并,您仍然会遇到冲突。
您需要该功能的示例是 Mavens 项目配置文件。
我觉得尤其是这个文件不应该被忽略或以其他方式从 scm 中排除。那你为什么需要那个?
我的猜测是您在 pom 中定义了指向本地资源的属性。如果是这样:将该属性移动到 "user.home"/.m2
中的 settings.xml
。这是他们的归宿。
命令git update-index --assume-unchanged filename
不能在两个分支中使用,这是一种暂时忽略文件的方法。当你修改文件,然后想切换或合并到其他分支时,git 会为你显示错误信息,因为你有 un-commit 个更改,这意味着你应该在切换前使用 git update-index --no-assume-unchanged filename
或合并分支。
针对你的情况,可以参考以下两种方式:
- 该文件不再需要做版本控制。所以你可以在
.gitignore
中添加文件,然后使用git rm --cached filename
取消跟踪它。 - 需要对文件做版本控制。合并分支时,可以使用
git merge branchname -X ours/theirs
使文件无效。