Git 卡在 master 上 | 合并

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

Git stuck on master | MERGING

git

提问by AspiringCanadian

There are two remotes assigned, originis used to pull the changes and harmeetis the production.

分配了两个遥控器,origin用于拉取更改和harmeet生产。

I tried git reset --hardbut as soon as I pull latest changes the status reverts to master | MERGINGand then I can't push latest code to harmeetbecause Git tells me everything is up to date. I am not sure what is wrong here.

我尝试过,git reset --hard但是一旦我拉取最新更改,状态就会恢复master | MERGING,然后我无法推送最新代码,harmeet因为 Git 告诉我一切都是最新的。我不确定这里有什么问题。

Git Status

Git 状态

回答by Scott Weldon

As mentioned in @Holger's comment, you can do git merge --abortto abort the merge. However, you might not want to do that. The merge happens because the remote (origin) has changes that you don't have locally. Your history might look something like this:

正如@Holger 的评论中所述,您可以git merge --abort中止合并。但是,您可能不想这样做。合并发生是因为远程 ( origin) 具有您在本地没有的更改。您的历史记录可能如下所示:

*--*--A--B--C [master, harmeet/master]
       \
        D--E [origin/master]

(Note that master== harmeet/master. I'll come to that in a minute.)

(请注意master== harmeet/master。我稍后会讲到。)

There are three solutions: merge, rebase, or force update.

有三种解决方案:merge、rebase 或 force update。

Merge

合并

The easiest solution would be to just complete the merge. To do so, resolve any conflicts in your editor, stage with git add ., and commit with git commit. Your history would then look like this:

最简单的解决方案是完成合并。为此,请解决编辑器中的任何冲突,使用git add .暂存并使用 提交git commit。您的历史记录将如下所示:

*--*--A--B---C [harmeet/master]
       \      \
        \      F [master]
         \    /
          D--E [origin/master]

and then you can git push origin masterto update originand git push harmeet masterto update harmeet.

然后你可以git push origin master更新origingit push harmeet master更新harmeet

Rebase

变基

If you want to keep a linear history, abort the merge and then do:

如果要保留线性历史记录,请中止合并,然后执行以下操作:

git pull --rebase

(If there are any conflicts, resolve them and continue with git rebase --continue.)

(如果有任何冲突,解决它们并继续git rebase --continue。)

Your history would then look like this:

您的历史记录将如下所示:

*--*--A--B--C [harmeet/master]
       \
        D--E [origin/master]
            \
             B'--C' [master]

You can then update originwith:

然后你可以更新origin

git push origin master

and force-update harmeetwith:

并强制更新harmeet

git push --force-with-lease harmeet master

Your final history would then be:

您的最终历史记录将是:

*--*--A--D--E--B'--C' [master, origin/master, harmeet/master]

Force-update

强制性升级

If you reallydon't want the changes from origin, you can do:

如果您真的不希望从 更改origin,您可以执行以下操作:

git push --force-with-lease origin master

and your history would look like this:

你的历史看起来像这样:

*--*--A--B--C [master, harmeet/master, origin/master]


If Git tells you that harmeet/masteris up-to-date, then it is at the same commit as your local master, unless someone has pushed to harmeet/mastersince your last fetch.

如果 Git 告诉你这harmeet/master是最新的,那么它与你的本地提交相同master,除非有人在harmeet/master你上次获取后推送到。

If your goal is to get the changes from origin(commits Dand E) to harmeet, then you'll need to either rebase or merge, and then push, as described above.

如果您的目标是将更改从origin(commitsDE)更改为harmeet,那么您将需要变基或合并,然后推送,如上所述。

回答by tolginho

I have detected on one of my colleagues machine master | MERGINGstatus happens if developer exists from merge commit description without any input.

我在我的一位同事上检测到master | MERGING如果开发人员在没有任何输入的情况下从合并提交描述中存在,则会发生机器状态。

At this stage, you will just need to send a commit and describe a description as follows:

在这个阶段,你只需要发送一个提交并描述如下描述:

git commit -m 'merge commit'

Other answers are mostly focused on rollback, however if your case to forward, you may use that solution.

其他答案主要集中在回滚上,但是如果您的案例要转发,您可以使用该解决方案。