相关文章推荐
火爆的草稿本  ·  pandas中DataFrame ...·  5 天前    · 
追风的鼠标  ·  【转】在'git ...·  1 周前    · 
挂过科的酱肘子  ·  JPA-EntityManager.merg ...·  3 周前    · 
绅士的抽屉  ·  知识点小计20240302--SQL ...·  1 月前    · 
儒雅的保温杯  ·  c# - ...·  9 月前    · 
强健的日记本  ·  Error:Conversion to ...·  12 月前    · 


问题

比如我们在 develop 分支执行下面的合并命令,去合并其他分支之后,我们突然不想合并了,要取消该怎么处理?

git命令怎么取消合并?_github

执行合并之后,会出现 MERGING

git命令怎么取消合并?_github_02

代码也有很多的变更

git命令怎么取消合并?_参考资料_03

解决

我们可以执行

git

官网是这样介绍这个命令的:我用谷歌翻译了一下

The second syntax (“git merge --abort”) can only be run after the merge has resulted in conflicts. git merge --abort will abort the merge process and try to reconstruct the pre-merge state. However, if there were uncommitted changes when the merge started (and especially if those changes were further modified after the merge was started), git merge --abort will in some cases be unable to reconstruct the original (pre-merge) changes. Therefore:

Warning: Running git merge with non-trivial uncommitted changes is discouraged: while possible, it may leave you in a state that is hard to back out of in the case of a conflict.

​git merge --abort​ ​​ 只能在合并导致冲突后运行。 ​ ​git merge --abort​ ​​ 将中止合并过程并尝试重建预合并状态。 但是,如果在合并开始时有未提交的更改(特别是如果在合并开始后进一步修改了这些更改), ​ ​git merge --abort​ ​ 在某些情况下将无法重建原始(合并前)更改。

git命令怎么取消合并?_github_04


执行完成之后,我们发现 MERGING 没了

git命令怎么取消合并?_参考资料_05

代码也恢复到之前的状态了:

git命令怎么取消合并?_官网_06

参考资料