使用 git merge 合并过程中冲突,撤销当前合并操作

Git 2020-02-26 阅读 606 评论 0

冲突的出现

使用 git 命令在合并其他分支,或者在当前分支合并git pull过程中出现冲突错误。

$ git merge test
Auto-merging branch.php
CONFLICT (content): Merge conflict in branch.php
Automatic merge failed; fix conflicts and then commit the result.

查看工作空间状态 git status

$ git status
On branch master
You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)

Unmerged paths:
  (use "git add <file>..." to mark resolution)

	both modified:   branch.php

no changes added to commit (use "git add" and/or "git commit -a")

取消当前合并

参考 git-merge 文档,使用--abort。将取消当前合并,回到合并前的状态。

中止当前的冲突解决过程,并尝试重构合并前状态。
如果合并开始时存在未提交的工作树更改,则git merge --abort在某些情况下将无法重构这些更改。因此,建议始终在运行git merge之前提交或存储更改。
当存在MERGE_HEAD时,git merge --abort等效于git reset --merge。

$ git merge --abort


最后更新 2020-02-26