git 如何撤消主分支的合并?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34638188/
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-19 11:40:39  来源:igfitidea点击:

How to undo merge of master branch?

gitgithubversion-controlmergegit-branch

提问by 14wml

I'm new Github so please forgive what may seem like an obvious question. I have an Experimentationbranch which is 24 commits ahead of the masterbranch.

我是新的 Github,所以请原谅这似乎是一个明显的问题。我有一个Experimentation分支,在该master分支之前有 24 次提交。

Following this tutorial, I merged the masterbranch with the Experimentationbranch like so:

按照本教程,我将master分支与Experimentation分支合并,如下所示:

git checkout master
git merge Experimentation

(There were no merge conflicts.)

(没有合并冲突。)

But then I realized that merging the two branches would not keep the commit history of the Experimentation branch and what I really wanted was to do a rebase (in order to keep the commit history of the Experimentation branch).

但后来我意识到合并两个分支不会保留实验分支的提交历史,我真正想要的是做一个 rebase(为了保留实验分支的提交历史)。

So my question is: how do I undo the merge of the master branch?

所以我的问题是:如何撤消主分支的合并?

I've already tried:

我已经尝试过:

$ git branch
      Experimentation
    * master
      pod-attempt

$ git merge --abort
      fatal: There is no merge to abort (MERGE_HEAD missing).

The "fatal" message confused me b/c I thought I didmerge the master branch.

“致命”消息让我感到困惑,我以为我确实合并了主分支。

采纳答案by Sazzad Hissain Khan

There is no ongoing mergepending so git is supposed to show you,

没有正在进行的merge挂起,所以 git 应该向你展示,

fatal: There is no merge to abort (MERGE_HEAD missing).

Now if you want to go back to previous state (state before you merged), try

现在,如果您想回到之前的状态(合并前的状态),请尝试

$ git branch
      Experimentation
    * master
      pod-attempt
$ git reset --hard HEAD~24

You are done!

你完成了!