简体   繁体   English

git rebase --continue 不起作用

[英]git rebase --continue won't work

I did git rebase master , fixed the conflicts reported in a file, and then git add the file to resolve the conflict.我做了git rebase master ,修复了文件中报告的冲突,然后git add文件来解决冲突。 Then I did git rebase --continue , and got this:然后我做了git rebase --continue ,得到了这个:

Applying: Fixed unit test应用:固定单元测试

No changes - did you forget to use 'git add'?没有变化 - 您是否忘记使用“git add”? If there is nothing left to stage, chances are that something else already introduced the same changes;如果没有任何东西可以上演,很可能其他东西已经引入了相同的变化; you might want to skip this patch.你可能想跳过这个补丁。

When you have resolved this problem, run "git rebase --continue".解决此问题后,运行“git rebase --continue”。 If you prefer to skip this patch, run "git rebase --skip" instead.如果您更喜欢跳过此补丁,请改为运行“git rebase --skip”。 To check out the original branch and stop rebasing, run "git rebase --abort".要检查原始分支并停止变基,请运行“git rebase --abort”。

Any idea what I am missing here?知道我在这里缺少什么吗? Should I do git rebase --skip?我应该做 git rebase --skip 吗?

If you are in Mac OS X, then first of all you should disable revisiond , as it can mess with files in your work tree in the middle of rebase, causing unpredictable and broken behavior:如果您使用的是 Mac OS X,那么首先您应该禁用revisiond ,因为它可能会在 rebase 中间弄乱您工作树中的文件,从而导致不可预测和损坏的行为:

git config --global core.trustctime false

The issue is explained in this article , and big thanks to @nickfalk who pointed it out.这个问题在这篇文章中有解释,非常感谢@nickfalk指出它。

As for your rebase, this kind of situation is not unusual in practice.至于你的rebase,这种情况在实践中并不少见。 Let's try to think through the steps of what's happening:让我们试着思考一下发生了什么的步骤:

  • When you rebase the current branch on top of another branch, git moves the HEAD to the other branch, and starts applying the unique commits you have in your current branch.当您将当前分支变基到另一个分支的顶部时,git 会将 HEAD 移动到另一个分支,并开始应用您在当前分支中的唯一提交。

  • While replaying one of those commits, you reached a conflict.在重播其中一个提交时,您遇到了冲突。 You resolved it, but as a result there are no changes to commit, nothing to replay in this commit.您解决了它,但结果是没有任何更改要提交,在此提交中没有可重播的内容。

Practically, this means that you rejected the changes in the current commit being replayed.实际上,这意味着您拒绝了正在重放的当前提交中的更改。 So, if you don't need anything from this commit, it's normal to skip it.因此,如果您不需要此提交中的任何内容,则跳过它是正常的。 So git rebase --skip makes sense here.所以git rebase --skip在这里是有意义的。

Breath, you're not going crazy!呼吸,你不会发疯! ;-= This is a known bug where OSX (if that is indeed what you're using) is messing with git, it is detailed here (not by me). ; - =这是一个已知的bug,其中OSX(如果这确实是你所使用的)与git的,它详细搞乱这里(不是我)。

Short story (ie the fix) is:短篇小说(即修复)是:

git config --global core.trustctime false

I had a similar problem in my project and solved by putting the --preserve-merges option to the rebase command.我在我的项目中遇到了类似的问题,并通过将--preserve-merges选项放入 rebase 命令来解决。 In my project, this problem was caused by a merge commit, which is an "empty commit".在我的项目中,这个问题是由合并提交引起的,它是一个“空提交”。 Using git rebase --preserve-merges it takes the merge commit and continues the merge without breaking the commit tree.使用git rebase --preserve-merges它需要合并提交并继续合并而不破坏提交树。

I tried all the methods but nothing worked for me.我尝试了所有方法,但对我没有任何效果。 If you are not in the middle of a rebase but git keeps complaining, then try the following.如果您不在 rebase 中,但 git 一直在抱怨,请尝试以下操作。 This worked for me for OSX.这对我来说适用于 OSX。

rm -fr ".git/rebase-apply"

It could well mean that the changes are already rebased.这很可能意味着更改已经重新定位。 Just check the git status.只需检查 git 状态。

None of the above suggestions worked.上述建议均无效。 I found out that I had this issue because I did a hard reset of the master branch, while my feature branch had some legacy master commits (don't asked me how - no idea :( ).我发现我遇到了这个问题,因为我对 master 分支进行了硬重置,而我的 feature 分支有一些遗留的 master 提交(不要问我如何 - 不知道 :( )。

I copied my changes out to a temporary directory, deleted my feature branch, copied them back in, and restarted from scratch.我将更改复制到一个临时目录,删除了我的功能分支,将它们复制回,然后从头开始。 Ugly but effective.丑陋但有效。 Not suggested if you're trying to keep more than one commit in your feature branch.如果您尝试在功能分支中保留多个提交,则不建议这样做。 Not suggested unless you have tried EVERYTHING ELSE .不建议,除非你已经尝试了EVERYTHING ELSE

UPDATE: This worked, but a better approach has been pointed out to me in the comments below.更新:这有效,但在下面的评论中向我指出了更好的方法。 Take a look.看一看。

git add . will unblock you from this state, but if you resolved all conflicts by accepting the incoming changes, there is no diff to add so git thinks the conflict wasn't resolved as far as the rebase is concerned.将解除对此状态的阻止,但是如果您通过接受传入的更改解决了所有冲突,则没有要添加的差异,因此 git 认为就 rebase 而言,冲突尚未解决。

I took a low brow approach that worked without relying on side effects of using mysterious git config changes etc:我采取了一种低调的方法,该方法不依赖于使用神秘的 git 配置更改等的副作用:

  • Added harmless content (eg // on one line) to each file in conflict (to give git something to add )向冲突中的每个文件添加无害的内容(例如//在一行中)(给 git add一些东西)
  • git add .
  • git rebase --continue
  • remove harmless comment删除无害评论

All sorted 🙂全部整理好🙂

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM