如何在Git中找回一个文件的冲突? [英] How to get back conflicts for one file in Git?

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

问题描述

我在合并后解决了部分冲突,但是我发现在当前冲突中,我保留了错误的代码部分.错误地完成了提交,并且(不是因为这个原因)我不能在解决此冲突之前撤消撤消操作.有什么方法可以让我在之前的冲突之前恢复过来吗?

I have solved part of the conflicts after merging, but I have figured out that on the current conflict I am keeping the wrong part of code. By mistake there have been done a commit, and (not because of that) I cannot go back with undo until before solving this conflict. Is there a way that I can get back to before previous conflict?

更详细:

  • 我已经解决了file1中的3个冲突
  • 我已经解决了file2中的5个冲突
  • 我已经解决了file3中的2个冲突,当解决了第三次冲突时,我保留了错误的代码部分.我犯了一个错误.如何恢复到file3中的第3个冲突之前或重做file3中的冲突?

推荐答案

git rerere有时可以选择

有几种方法可以解决此问题.例如,如果您在打开之前已打开 git rerere 开始解决冲突后,您将能够从头开始重做合并,并使用git rerere自动 重新应用冲突解决方案 .

git rerere can sometimes be an option

There are several ways that you could have resolved this. For example, if you had turned on git rerere before you started resolving conflicts, you would have been able to redo the merge from scratch and re-apply your conflict resolutions automatically with git rerere.

但是,由于您已经提交了更改,因此您实际上可以使用git checkout <revision> -- <file>重新应用以前的冲突解决方案,其中<revision>是当前合并提交的提交sha:

However, since you're already committed your changes, you can actually reapply your previous conflict resolutions anyways by using git checkout <revision> -- <file>, where <revision> is the commit sha for your current merged commit:

# First, let's undo your merge
git reset --hard <previousCommit>

# Next, redo the merge
git merge <branch>

# Next, we'll reapply your previous resolutions
# from the previous merge "PM", for files 1 and 2
git checkout PM -- file1
git checkout PM -- file2

# Next, go ahead and fix the conflicts for file 3...

# When you're done, commit
git commit

说明

命令

git checkout <revision> -- <file>

将从<revision>中签出<file>的版本.您可以从官方文档中找到有关此文档的更多文档. a>.

will checkout the version of <file> from <revision>. You can find more documentation about this from the official documentation.

这篇关于如何在Git中找回一个文件的冲突?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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