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
Git stuck on master | MERGING
提问by AspiringCanadian
There are two remotes assigned, origin
is used to pull the changes and harmeet
is the production.
分配了两个遥控器,origin
用于拉取更改和harmeet
生产。
I tried git reset --hard
but as soon as I pull latest changes the status reverts to master | MERGING
and then I can't push latest code to harmeet
because Git tells me everything is up to date. I am not sure what is wrong here.
我尝试过,git reset --hard
但是一旦我拉取最新更改,状态就会恢复master | MERGING
,然后我无法推送最新代码,harmeet
因为 Git 告诉我一切都是最新的。我不确定这里有什么问题。
回答by Scott Weldon
As mentioned in @Holger's comment, you can do git merge --abort
to 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 master
to update origin
and git push harmeet master
to update harmeet
.
然后你可以git push origin master
更新origin
和git 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 origin
with:
然后你可以更新origin
:
git push origin master
and force-update harmeet
with:
并强制更新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/master
is up-to-date, then it is at the same commit as your local master
, unless someone has pushed to harmeet/master
since your last fetch.
如果 Git 告诉你这harmeet/master
是最新的,那么它与你的本地提交相同master
,除非有人在harmeet/master
你上次获取后推送到。
If your goal is to get the changes from origin
(commits D
and E
) to harmeet
, then you'll need to either rebase or merge, and then push, as described above.
如果您的目标是将更改从origin
(commitsD
和E
)更改为harmeet
,那么您将需要变基或合并,然后推送,如上所述。
回答by tolginho
I have detected on one of my colleagues machine master | MERGING
status 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.
其他答案主要集中在回滚上,但是如果您的案例要转发,您可以使用该解决方案。