Git 撤销合并尝试

我有一个工作目录(# 1) ,里面有供应商目录(# 2)。有一个依赖项,我想在不使用编曲器的情况下手动提取(npm/gem 的 php 版本)。我在 # 1中工作,还没有保存/提交更改,当我决定在 # 2中更新库时。我导航到供应商/我的名字,并做了 git 拉存储库。

不幸的是,它开始拉合并到 # 1,而不是在供应商文件夹中创建新的目录。

现在我有了:

  • 包含我的更改的 # 1文件夹
  • # 1文件夹中的文件我不想从错误的存储库
  • # 1 merge 冲突,如 comper.json、 Readme.md... (常规文件)

我想“撤消”这最后一个 git 拉,而不会丢失我对文件夹 # 1所做的任何更改。我怎么能这么做?

43745 次浏览

git merge --abort might be what you're looking for.

Modern Git:

git merge --abort

Older:

git reset --merge

Old-school (warning: will discard all your local changes):

git reset --hard

But actually, it is worth noticing that git merge --abort is only equivalent to git reset --merge given that MERGE_HEAD is present. This can be read in the git help for merge command.

git merge --abort is equivalent to git reset --merge when MERGE_HEAD is present.

After a failed merge, when there is no MERGE_HEAD, the failed merge can be undone with git reset --merge but not necessarily with git merge --abort, so they are not only old and new syntax for the same thing. Personally I find git reset --merge much more useful in everyday work.

With Git 2.10 (Q3 2016), you will know what to do, because git status will propose the git merge --abort option.

See commit b0a61ab (21 Jul 2016) by Matthieu Moy (moy).
(Merged by Junio C Hamano -- gitster -- in commit 5a2f4d3, 03 Aug 2016)

status: suggest 'git merge --abort' when appropriate

We already suggest 'git rebase --abort' during a conflicted rebase.
Similarly, suggest 'git merge --abort' during conflict resolution on 'git merge'.