Git重新分配到master失败,如何解决? [英] Git rebase a branch onto master failed, how to resolve?

查看:1219
本文介绍了Git重新分配到master失败,如何解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究一个远程git仓库的本地副本。
我在本地副本上创建了一个分支,我们称它为'my_branch'。
我在my_branch上犯过几次。



我最近将'my_branch'推送到远程。但是我不知道其他人向远程主服务器添加了一个版本。所以,我把它提交给我的本地主人。

因此...长话短说,我的本地回购看起来像这样(我试图使用图解规则<这里)。

  --C0 ---------- C7--(本地主)
\
--C1-C2-C3--(本地my_branch)

--C4-C5-C6--(本地sandbox_branch)

我希望它看起来像:

  --C0 -------------- C7 - (本地主人)
\
--C1'-C2'-C3' - (本地my_branch)
\
--C4'-C5'- C6' - (local sandbox_branch)

我试图重新绑定my_branch ONTO local master,但是我得到这个错误消息(我正在使用一个称为GitX的可视化工具):
分支主重新分配HEAD时出错。

命令:git rebase refs / heads / master

看来我无法创建一个rebase-apply目录,而
我不知道你是否在中间的补丁程序或其他
rebase。如果不是这样,请
rm -fr /my_project_directory/.git/rebase-apply
并再次运行我。如果您在那里仍然有
的价值,我会停下来。

我做错了什么?我该如何处理?如果我要在命令行上执行此操作,那么使我能够进入上图中的状态的命令是什么?

更新1



顺便说一下,我并不是处于应用程序补丁或其他基准的中间......至少不是故意的。
在我推后,我发现遥控器被更新后,我做了一次提取。难道这已经做了什么让GitX认为我正处于应用程序补丁或其他rebase的中间吗?



我也更新了图表,使其更加准确。 my_branch有一个分支。我没有把它列入原来的问题B / C中,我认为这不重要。我包括以防万一......



更新2



...'local'和'remote'的主树看起来像我绘制的图,但它没有sandbox_branch。

解决方案git rebase已经找到了一个 .git / rebase-apply 目录,因此推测你可能正处于rebase的中间。如果在以前的重新组合中发生冲突并且未完成重建,则会发生这种情况;即你没有运行 git rebase --abort git rebase --skip git rebase --continue (解决冲突后的最后一个)。



无论如何,这无关紧要如果你认为你没有运行git rebase,那么请注明状态。只需 rm -fr /my_project_directory/.git/rebase-apply 作为帮助建议,您现在应该可以进行rebase。



但是等等。既然你说你已经将你的分支发布到远程仓库,你不应该试图将master分配给它。事实上,如果您的远程设置拒绝非快速提交(这似乎是一个通常推荐的最佳做法),那么您甚至无法将重新进行的更改推送到您的远程。一般来说,尝试修改一个提交(这是 git rebase 的作用)后将其发布到远程服务器是不好的做法。


I've been working on a local copy of a remote git repo. I created a branch on my local copy, let's call it 'my_branch'. I've committed a few times on my_branch.

I recently pushed 'my_branch' to remote. However I didn't know that someone else added a version to the remote master. So, I fetched it to my local master.

So...long story short, my local repo looks like this (I'm trying to use the diagraming convention here) .

 --C0--------------C7--  (local master)
      \
       --C1-C2-C3--     (local my_branch)
             \
              --C4-C5-C6--     (local sandbox_branch)

I want it to look like:

 --C0--------------C7--  (local master)
                      \
                       --C1'-C2'-C3'--     (local my_branch)
                             \
                              --C4'-C5'-C6'--     (local sandbox_branch)

I tried to rebase my_branch ONTO local master but I got this error message (I'm using a visual tool for git called GitX):

Rebase Failed!
There was an error rebasing HEAD with branch 'master'.

command: git rebase refs/heads/master

It seems that I cannot create a rebase-apply directory, and
I wonder if you are in the middle of patch application or another
rebase.  If that is not the case, please
    rm -fr /my_project_directory/.git/rebase-apply
and run me again.  I am stopping in case you still have something
valuable there.

What am I doing wrong? How should I handle this? If I were to do this on the command line what is the command to get me to the state in the diagram above?

UPDATE 1

BTW, I'm not in the middle of an application patch or another rebase...at least not intentional. After I found out that remote was updated AFTER I pushed, I did a fetch. Could that have done anything to make GitX think that I'm in the middle of an application patch or another rebase?

I've also updated the diagram to be more accurate. There is a branch off of my_branch. I didn't include it in the original question b/c I didn't think that it would matter. I'm including just in case...

UPDATE 2

FYI...The master tree for 'local' and for 'remote' looks like the diagram that I drew, except it doesn't have the sandbox_branch.

解决方案

git rebase has found a .git/rebase-apply directory and so presumes that you might be in the middle of a rebase. This would have happened if there was a conflict during a previous rebase and the rebase was not finished; i.e. you did not run one of git rebase --abort, git rebase --skip or git rebase --continue (the last one after resolving the conflict).

Anyway, it does not matter how you ended up in this state if you don't think you ran git rebase at all. Simply rm -fr /my_project_directory/.git/rebase-apply as the help suggests and you should be able to do the rebase now.

But wait. Since you say that you have already published your branch to the remote repository, you should not try to rebase master onto it. In fact, if your remote is set to deny non-fast-forward commits (which seems to be a generally recommended best practice), you'll not even be able to push the rebase'd changes to your remote. In general, it is a bad practice to try to modify a commit (which is what git rebase does) after you have published it to a remote.

这篇关于Git重新分配到master失败,如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆