取消git merge,但保留本地更改

Mat*_*ner 8 git

我开始进行git merge,但进行了要保留的本地更改。我不再想要合并,而是继续处理本地更改。我该怎么做呢?

小智 12

根据对类似问题的回答,从 Git 2.23(2019 年第 3 季度)开始,您可以使用:

git merge --quit

这会:

  • 忘记当前正在进行的合并。
  • 保持索引和工作树不变。


Mic*_*ens 7

语言众所周知是模棱两可的。:-)当您说“保持本地变化”时,您可能会表示:

  1. 将所有当前更改保留在工作目录中,无论您是手动编辑这些文件还是将其放入其中的合并。要么
  2. 放弃合并带来的任何更改,并保留您引入的所有更改。

这个简单的解决方案解决了第(1)点:

$ git stash save
$ git stash pop
Run Code Online (Sandbox Code Playgroud)

这是显示影响的笔录:

$ git status
On branch stuff-217/apply-new-config-details
All conflicts fixed but you are still merging.  <<<<<< notice this line!

Changes to be committed:
        modified:   package.json
        modified:   src/wallabyTest.ts
        modified:   wallaby.js

$ git stash save
Saved working directory and index state WIP on stuff-217/apply-new-config-details...

$ git status
On branch stuff-217/apply-new-config-details
nothing to commit, working tree clean

$ git stash pop
On branch stuff-217/apply-new-config-details
                                             <<<<<< no longer in the merge!
Changes not staged for commit:
        modified:   package.json
        modified:   src/wallabyTest.ts
        modified:   wallaby.js
Run Code Online (Sandbox Code Playgroud)

  • 解决方案#1对我不起作用...似乎它迫使我在执行存储之前进行合并:`(branch|MERGING) =&gt; git stash save src/test/java/File.java: 需要合并` (2认同)