git Git撤消合并尝试

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18693006/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 16:54:39  来源:igfitidea点击:

Git undo merge attempt

gitgit-mergegit-pull

提问by ewooycom

I have working directory (#1) which has vendor directory(#2) in it. There is one dependency which I wanted to pull manually without composer (php version of npm/gem). I was working in #1, haven't saved/commited changes, when I decided I want to update library in #2. I navigated to vendor/myname, and did git pull repository.

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

Unfortunately it started to pull and merge to #1, instead of creating new directory in vendor folder.

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

Now I have:

我现在有:

  • #1 folder with my changes
  • #1 folder with files I don't want from wrong repository
  • #1 merge conflicts such as composer.json, Readme.md... (general files)
  • #1 包含我更改的文件夹
  • #1 文件夹中的文件我不想从错误的存储库中获取
  • #1 合并冲突如composer.json、Readme.md...(通用文件)

I want to "undo" this last git pull without loosing any changes I did to folder #1. How can I do this?

我想在不丢失对文件夹 #1 所做的任何更改的情况下“撤消”最后一次 git pull。我怎样才能做到这一点?

回答by aragaer

git merge --abortmight be what you're looking for.

git merge --abort可能就是你要找的。

回答by Martin G

Modern Git:

现代 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 --abortis only equivalent to git reset --mergegiven that MERGE_HEADis present. This can be read in the git help for merge command.

但实际上,值得注意的git merge --abort是,仅相当于给git reset --mergeMERGE_HEAD存在。这可以在合并命令的 git 帮助中阅读。

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 --mergebut not necessarily with git merge --abort, so they are not only old and new syntax for the same thing. Personally I find git reset --mergemuch more useful in everyday work.

合并失败后,如果没有MERGE_HEAD,失败的合并可以用 撤消,git reset --merge但不一定用git merge --abort因此它们不仅是同一事物的新旧语法。我个人觉得git reset --merge在日常工作中更有用。

回答by VonC

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

使用 Git 2.10(2016 年第 3 季度),您将知道该怎么做,因为git status会提出git merge --abort选项。

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

请参阅Matthieu Moy ( )提交的 b0a61ab(2016 年 7 月 21 日)(由Junio C Hamano合并-- --commit 5a2f4d3,2016 年 8 月 3 日)moy
gitster

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'.

status:git merge --abort在适当的时候建议 ' '

我们已经git rebase --abort在冲突的 rebase 中建议了 ' '。
同样,git merge --abort在“ ”的冲突解决期间建议“ git merge”。