如何在解决冲突的过程中进行长时间的Git合并 [英] How to commit a long Git merge in the middle of resolving conflicts

查看:76
本文介绍了如何在解决冲突的过程中进行长时间的Git合并的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与300多个冲突文件进行了大合并。我想使用mergetool解决这些问题,但是我无法一口气完成所有工作。如何提交合并,然后稍后再返回并继续相同的合并?通常,如果索引中有冲突,似乎git不允许您提交。

I have a big merge going on with over 300 conflicting files. I want to resolve these using mergetool, but there's no way I'm going to finish it all in one sitting. How can I commit the merge and then come back later and continue the same merge? Normally it seems git doesn't allow you to commit if there are conflicts in the index.

推荐答案

我假设不能一口气做这件事,实际上是想在我完成之前做一些其他事情,因为否则您可以将部分解决的合并留在工作树中。

I'm assuming by "can't do it in one sitting" you actually mean "want to do some other things before I finish" - since you could just leave the partially resolved merge in your work tree otherwise.

首先,在遇到麻烦之前,请注意,您可以简单地创建存储库的另一个克隆-部分解析的合并可以保留在其中,而您可以在另一个中进行其他工作。

First, before you go to any trouble, note that you could simply create another clone of the repository - the partially resolved merge can stay in one, and you can do other work in another.

话虽如此,如果您确实想保存所做的工作以部分解决合并问题,我最好的建议是使用 git rerere (重新使用记录的解决方案)。

All that said, if you really do want to save the work you've done to partially resolve a merge, my best suggestion is to use git rerere (REuse REcorded REsolutions).

要开始使用,请确保将 rerere.enabled 设置为true -涵盖了大多数正常的用例。这会导致 git rerere 在合并冲突发生后立即自动运行-那时,您将看到以下形式的消息:为'< path> ;'。提交合并后,它也会自动运行;那么您将看到为< path>记录的分辨率形式的邮件。。然后,当出现相同的冲突块时,可以重新使用这些分辨率。

To get started, make sure that rerere.enabled is set to true - that will cover most of the normal use cases. It causes git rerere to automatically be run immediately after merge conflicts happen - at that point you will see messages of the form Recorded preimage for '<path>'. It's also run automatically when you commit a merge; then you'll see messages of the form Recorded resolution for '<path>'.. The resolutions can then be reused later when the same conflicted hunks appear.

现在,在您的用例中,将发生第一个自动触发-将记录原图像。但是您还不准备提交合并,因此在解决了一些冲突文件并将它们标记为已解决(将它们添加到索引中)之后,您可以运行 git rerere (否参数)直接 。它将记录您标记为已解决的所有问题的解决方案,但忽略仍未解决的问题。然后,您可以简单地销毁尝试的合并( git reset --merge ),下一次尝试时,记录的分辨率将被重用!

Now, in your use case, the first automatic trigger will happen - the preimages will be recorded. But you're not ready to commit your merge, so after resolving some conflicted files and marking them as resolved (adding them to the index) you can instead run git rerere (no arguments) directly. It will record the resolutions for everything you've marked as resolved, but ignore whatever's still unresolved. You can then simply destroy the attempted merge (git reset --merge), and the next time you attempt it, the recorded resolutions will be reused!

这篇关于如何在解决冲突的过程中进行长时间的Git合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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