git:如何重做合并冲突解决方案(在提交合并之前)? [英] git: How to redo a merge conflict resolution (before committing the merge)?

查看:507
本文介绍了git:如何重做合并冲突解决方案(在提交合并之前)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了

git merge FETCH_HEAD

并且,在git告诉我一个文件中存在冲突之后,我做了一个

git mergetool

在我的案例中,它运行SourceGear DiffMerge作为GUI合并工具.保存合并的文件后,我立即意识到自己犯了一个严重的错误.我只想忘记合并,然后全部完成.

由于我还没有执行"git add",更不用说提交任何东西了,我以为我可以消除我的错误并像这样容易地重做合并:

git reset FILENAME
git merge FETCH_HEAD
git mergetool

这不起作用.这次"git merge"告诉我

fatal: You have not concluded your merge (MERGE_HEAD exists).
Please, commit your changes before you can merge.

但是我当然不想提交搞砸的合并. "git mergetool"抱怨

No files need merging

我猜我在"git reset"命令中犯了一个错误.正确的方法是什么?

添加:

我做了

git merge --abort

然后再次:

git merge FETCH_HEAD

这产生了

error: Your local changes to the following files would be overwritten by merge: ...

git status

说:

On branch ....
Your branch is up-to-date with ......
Changes not staged for commit:
    modified:   nVP.ini
Untracked files:
    nVP.ini.orig
no changes added to commit (use "git add" and/or "git commit -a")

只是一个主意:简单地对nVP.ini进行git checkout可以使合并之前的情况恢复正常?

解决方案

要在提交前撤消错误的冲突解决方法,请git checkout -m -- $thefile.

$ git merge 3fac3
Auto-merging file.txt
CONFLICT (content): Merge conflict in file.txt
Automatic merge failed; fix conflicts and then commit the result.
$ vi file.txt         # fix all the conflicts. do it wrong.
$ git add file.txt    # <--- ooops
$ git checkout -m -- file.txt    # <--- the correct un-oops-ifier here

file.txt返回到自动失败合并状态.

请注意,您还可以指定冲突报告样式,因此,如果您通常使用默认的2-diff样式,但是却感到困惑,也想查看原始样式,则可以git checkout -m --conflict diff3 -- file.txt.. >

I did a

git merge FETCH_HEAD

and, after git told me that there is a conflict in one file, I did a

git mergetool

which in my case runs SourceGear DiffMerge as a GUI mergetool. Immediately after saving the merged file, I realized that I made a bad mistake. I just want to forget the merge and do it all over.

Since I didn't have executed a "git add" yet, let alone committed anything, I thought I could erase my mistake and redo the merge easily like this:

git reset FILENAME
git merge FETCH_HEAD
git mergetool

This does not work. "git merge" by this time tells me

fatal: You have not concluded your merge (MERGE_HEAD exists).
Please, commit your changes before you can merge.

But of course I don't want to commit the screwed-up merge. "git mergetool" complains

No files need merging

I guess I made a mistake at the "git reset" command. What is the proper way to do this?

ADDING:

I did

git merge --abort

then again:

git merge FETCH_HEAD

This yielded

error: Your local changes to the following files would be overwritten by merge: ...

git status

says:

On branch ....
Your branch is up-to-date with ......
Changes not staged for commit:
    modified:   nVP.ini
Untracked files:
    nVP.ini.orig
no changes added to commit (use "git add" and/or "git commit -a")

Just an idea: Would simply a git checkout of nVP.ini bring back the situation before the merge?

解决方案

To undo a bad conflict resolution before committing, git checkout -m -- $thefile.

$ git merge 3fac3
Auto-merging file.txt
CONFLICT (content): Merge conflict in file.txt
Automatic merge failed; fix conflicts and then commit the result.
$ vi file.txt         # fix all the conflicts. do it wrong.
$ git add file.txt    # <--- ooops
$ git checkout -m -- file.txt    # <--- the correct un-oops-ifier here

and file.txt is back to the failed-automerge state.

Note that you can also specify the conflict-reporting style, so if you ordinarily do the default two-diff style but you've got a baffling one and want to see the original too, you can git checkout -m --conflict diff3 -- file.txt.

这篇关于git:如何重做合并冲突解决方案(在提交合并之前)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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