git rebase冲突,如何删除在HEAD中删除的所有冲突文件 [英] git rebase conflicts, how to delete all conflicting files that were deleted in the HEAD

查看:407
本文介绍了git rebase冲突,如何删除在HEAD中删除的所有冲突文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在某些情况下,我正在尝试根据我的分支重新建立分支.但是在master上进行了一些更改,删除了大部分代码库(这很好,是可以预期的,并且已经讨论过).现在,我正在根据主服务器更改更改,但是我收到了疯狂的文件冲突,提示说 CONFLICT (modify/delete): someFile.fileType deleted in HEAD and modified in added commitName. Version added commitName of someFile.fileType left in tree. 手动处理10个文件就可以了,但是我有1000多个文件.如何git rm这些文件并继续重新设置基准?

Some context, I am trying to rebase my branch off master. But there were some changes done on master that delete a large portion of the code base (this is fine and was expected and talked about). Now I am rebasing my changes off master but I am getting an insane amount of file conflicts that say CONFLICT (modify/delete): someFile.fileType deleted in HEAD and modified in added commitName. Version added commitName of someFile.fileType left in tree. Doing things manually for like 10 files is fine but I have over 1000 of these files. How can I git rm these files and continue rebasing?

一些额外的信息: 我运行了以下命令 git rebase master

Some extra info: I ran the following command git rebase master

推荐答案

该方法非常简单,但是此方法的 application 需要一些注意,因为它很容易产生可怕的结果.您需要做的是识别索引中处于哪个阶段的文件,然后相应地更新索引.

The method is simple enough, but the application of this method requires some care, as it can produce terrible results easily. What you need to do is to identify which files exist at which stage(s) in the index, and then update the index accordingly.

如您所说,您有一个:

CONFLICT (modify/delete): someFile.fileType deleted in HEAD and modified in ...

因此,您将拥有一个文件,该文件存在于 base 提交中(在索引的第1阶段),并且存在于 other 提交中(在索引的第3阶段). ),但不在 HEAD 提交中(索引的第2阶段).该文件也将存在于工作树中.

Hence you will have a file that exists in the base commit (at stage 1 in the index), and exists in the other commit (stage 3 in the index), but not in the HEAD commit (stage 2 in the index). That file will also exist in the work-tree.

要找出索引中哪些文件处于哪个阶段,请运行git ls-files --stage.然后,您需要更改索引内容以解决任何冲突并确定要提交的内容.如果您希望通过在最后一次提交中删除 文件来解决此冲突,则只需运行git rm someFile.fileType,它将删除所有索引条目,文件的树状版本.

To find out which files are in the index, under which stages, run git ls-files --stage. You then need to alter the index contents to resolve any conflicts and determine what will be committed. If you wish to resolve this conflict by removing the file in the final commit, you can simply run git rm someFile.fileType, which will remove all of the index entries and the work-tree version of the file as well.

因此,作为一种非常作弊的方法,该可以起作用:

Hence, as a very cheat-y method, this could work:

git ls-files --stage | awk $'/ 3\t/ { print $4 }' | xargs git rm

对此要非常小心!如果您盲目地使用一些您不了解的食谱,则可能会烤出有毒的蛋糕.请注意,这完全忽略了同一文件是否具有Stage-2条目,而仅在索引中查找Stage-3条目.因为其中awk在此处用空格分隔字段,所以它也对任何包含空格的路径名都有不当行为.

Be very careful with this! If you blindly apply some recipe you don't understand, you may bake a poisonous cake. Note that this totally ignores whether the same file has a stage-2 entry, and looks only for a stage-3 entry in the index. It also misbehaves for any path name that has whitespace in it, since awk is field-separating by whitespace here.

请注意,所有 resolved 文件都在索引中,处于阶段0,因此,如果除了修改/删除冲突以外,您还有其他任何冲突,可以先手动解决它们,然后使用上述命令来解决git rm其余的.

Note that all resolved files are in the index as stage zero, so if you have any conflicts other than the modify/delete ones, you can resolve them manually first, then use the above command to git rm the remaining ones.

这篇关于git rebase冲突,如何删除在HEAD中删除的所有冲突文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆