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

git: How to redo a merge conflict resolution (before committing the merge)?

我做了一个

git merge FETCH_HEAD

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

git mergetool

在我的例子中,它作为 GUI mergetool 运行 SourceGear DiffMerge。保存合并后的文件后,我立即意识到我犯了一个严重的错误。我只想忘记合并并重新做一遍。

因为我还没有执行 "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")

只是一个想法:简单地 git 检查 nVP.ini 是否可以恢复合并前的情况?

要在提交之前撤消错误的冲突解决方案,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回到失败自动合并状态。

请注意,您还可以指定冲突报告样式,因此,如果您通常使用默认的双差异样式,但遇到了一个莫名其妙的样式,并且还想查看原始样式,则可以这样做

git checkout -m --conflict diff3 -- file.txt

我遇到了同样的问题,

dev 中合并了一个分支,在冲突解决期间删除了另一个分支更改。

我为此使用了 cherry-pick :

git cherry-pick {merge commit sha of missing branch code} -m 1

我能够重做整个冲突解决过程。

正是我要找的,但我想我要指出的是,如果您是更喜欢 git restore 而不是 git checkout 的人之一,则等效命令是:

git restore --merge -- <filepath>

git restore --conflict=diff3 -- <filepath>