git:如何重做合并冲突解决方案(在提交合并之前)?

use*_*428 4 git merge

我做了一个

git merge FETCH_HEAD
Run Code Online (Sandbox Code Playgroud)

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

git mergetool
Run Code Online (Sandbox Code Playgroud)

在我的例子中,它将SourceGear DiffMerge作为GUI mergetool运行.保存合并文件后,我意识到我犯了一个错误.我只想忘记合并并全力以赴.

由于我还没有执行过"git add",更不用说任何事了,我想我可以删除我的错误并轻松地重做合并:

git reset FILENAME
git merge FETCH_HEAD
git mergetool
Run Code Online (Sandbox Code Playgroud)

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

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

但当然我不想犯下搞砸的合并."git mergetool"抱怨道

No files need merging
Run Code Online (Sandbox Code Playgroud)

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

并补充说:

我做到了

git merge --abort
Run Code Online (Sandbox Code Playgroud)

然后再说:

git merge FETCH_HEAD
Run Code Online (Sandbox Code Playgroud)

这产生了

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

git status
Run Code Online (Sandbox Code Playgroud)

说:

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")
Run Code Online (Sandbox Code Playgroud)

只是一个想法:nVP.ini的简单结帐会在合并之前恢复情况吗?

jth*_*ill 13

要在提交之前撤消错误的冲突解决方案,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
Run Code Online (Sandbox Code Playgroud)

file.txt返回到失败的自动注册状态.

请注意,您还可以指定冲突报告样式,因此如果您通常使用默认的双差异样式,但是您有一个令人困惑的样式并且想要查看原始样式,则可以git checkout -m --conflict diff3 -- file.txt.