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

标签 git merge

我做了一个

git merge FETCH_HEAD

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

git mergetool

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

因为我还没有执行“git add”,更不用说提交任何东西了,我想我可以消除我的错误并像这样轻松地重做 merge :

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.

但是我当然不想提交搞砸的 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 是否可以恢复 merge 前的情况?

最佳答案

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

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

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

关于git:如何重做 merge 冲突解决方案(在提交 merge 之前)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29608028/

相关文章:

c - C 中的合并排序编译,但不排序

git - 从 vscode 中的 git 中删除 node_modules

git - 尝试使用 .gitignore 文件忽略 .log 文件

git子模块: track corresponding branch in submodule?

c# - '无法使用合并将类型 'void' 隐式转换为 'System.Data.DataTable'

go - go语言读取并合并两个yaml文件

git - 我如何告诉 Git 忽略除子目录之外的所有内容?

bash - 如何检查 git merge 是否真的在多 repo bash 脚本中进行了 merge

Python Pandas 仅合并某些列

java - 通过插入合并 2 个二叉搜索树