git Git变基失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34695044/
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 rebase failing
提问by Bunker
I'm trying to rebase the work of a colleague.
我正在尝试重新调整同事的工作。
First, I get a ton of conflicts where <<<<< head seams to contain the new code.
首先,我遇到了大量冲突,其中 <<<<< 头部接缝以包含新代码。
Then after a while I get the following error:
然后过了一会儿,我收到以下错误:
fatal: update_ref failed for ref 'refs/heads/dev_504':
cannot lock ref 'refs/heads/dev_504': ref refs/heads/dev_504 is at
XXXXXXX
but expected XXXXXXXX
Could not move back to refs/heads/dev_504
Then if I try to continue anyway I get the following error:
然后,如果我尝试继续,我会收到以下错误:
fatal: cannot resume: .git/rebase-apply/final-commit does not exist.
How can I fix this so the rebase won't give an error?
我该如何解决这个问题,以便 rebase 不会出错?
回答by Slim KTARI
You can run
git rebase --abort
to completely undo the rebase. Git will return you to your branch's state as it was before git rebase was called.You can run
git rebase --skip
to completely skip the commit. That means that none of the changes introduced by the problematic commit will be included. It is very rare that you would choose this option.You can fix the conflict.
Failing that, you should re-create your branch or you can be able to remove the .git/rebase-merge directory, which contains the rebase state.
您可以运行
git rebase --abort
以完全撤消变基。Git 会让你回到你的分支的状态,就像在调用 git rebase 之前一样。您可以运行
git rebase --skip
以完全跳过提交。这意味着不会包含由有问题的提交引入的任何更改。您很少会选择此选项。您可以解决冲突。
如果失败,您应该重新创建您的分支,或者您可以删除包含 rebase 状态的 .git/rebase-merge 目录。
回答by Alim ?zdemir
Apparently the branch onto which you want to rebase, was also rebased between the time you branched off, maybe cleaning history up or rebasing on yet another branch. If so, you need to:
显然,您要重新定位的分支也在您分支的时间之间重新定位,可能是清理历史记录或重新定位到另一个分支。如果是这样,您需要:
- abort, current mess:
git rebase --abort
- to be current:
git fetch
now the interesting part:
git rebase --onto BUDDY_BRANCH YOUR_BRANCH~ YOUR_BRANCH
- 中止,当前的混乱:
git rebase --abort
- 成为当前:
git fetch
现在有趣的部分:
git rebase --onto BUDDY_BRANCH YOUR_BRANCH~ YOUR_BRANCH
e.g. you branched of your local master(checkout of origin/master), a new branch test_branch(which you now want to update with current origin/master)
例如,你分支了你的本地master(检出 origin/master),一个新的分支test_branch(你现在想用当前的 origin/master 更新)
git rebase --onto master test_branch~ test_branch
What this does is in simple terms, it takes your branches initial parent commit, finds it's counterpart in current master and rebases based on that.
这做的很简单,它需要你的分支初始父提交,在当前的 master 中找到它的对应物,并基于它重新定位。
回答by ahidri
When you are updating your local branch with the another branch, you must resolve conflicts by choosing between your modifications and theirs. After resolving conflicts you can continue your rebasing by writing this git command :
当你用另一个分支更新你的本地分支时,你必须通过在你的修改和他们的修改之间进行选择来解决冲突。解决冲突后,您可以通过编写以下 git 命令来继续进行变基:
git rebase --continue
git rebase --continue
In case when you want to abort your action of rebasing you can write this git command :
如果您想中止变基操作,您可以编写以下 git 命令:
`git rebase --abort`