Git rebase will not continue after a delete/modify

2019-03-22 19:07发布

I'm in the middle of a rebase of my master to a stage branch

git checkout stage
git rebase master

At some time I deleted two files then modified the two files according to GIT.

warning: too many files, skipping inexact rename detection
CONFLICT (delete/modify): test-recommendation-result.php deleted in HEAD and modified in [Bug] Fix test recommender. Version [Bug] Fix test recommender of test-recommendation-result.php left in tree.
CONFLICT (delete/modify): test-recommendation.php deleted in HEAD and modified in [Bug] Fix test recommender. Version [Bug] Fix test recommender of test-recommendation.php left in tree.
Failed to merge in the changes.
Patch failed at 0015.

I want to say "Yeah git, go ahead and delete those files" so ....

git rm test-recommendation-result.php
git rm test-recommendation.php
git rebase --continue

Git says:

Applying [Bug] Fix test recommender
No changes - did you forget to use 'git add', Stupid?

When you have resolved this problem run "git rebase --continue".
If you would prefer to skip this patch, instead run "git rebase --skip".
To restore the original branch and stop rebasing run "git rebase --abort".

I say "Don't call me "Stupid" and just do what I told you to do!"

We are now at a standoff. Who is right and how do I fix this?

4条回答
孤傲高冷的网名
2楼-- · 2019-03-22 19:35

I hit this when a commit added a binary file that conflicted with an existing file.

I got by it by:

  • deleting the existing file,
  • making a single character change to a comment in a different file, and
  • "git add" ing that irrelevant change.

Git was happy again. :)

查看更多
做个烂人
3楼-- · 2019-03-22 19:38

There is not one magic sequence of commands to always run to solve this situation. If there were, GIT's developers would just perform that action and not bother the user.

Consider that this error can also happen if you're cherry picking / transplanting / backporting changes that affect a file that was re-factored or renamed.

For example, say that you have branch called support/1.0 that looks like this:


    com.somewhere.package-a/
      MyClass.java
      MyOtherClass.java

Now, suppose that between versions 1.0 and 1.5, this got refactored. So now release/1.5 looks like this:


    com.somewhere.package/
      a/
        MyClass.java
        ANewClass.java
      b/
        MyOtherClass.java

Now, let's say that you have a feature branch from release 1.5 that you're trying to back-port to a feature branch based off of support/1.0. In that commit, there were changes to all three files from release 1.5 (MyClass.java, ANewClass.java, and MyOtherClass.java).

If you try to use rebase or plain cherry pick to help with the back-port, one of two things may happen:

  • If the files got renamed as part of the changes being transplanted, or among the immediate parent commits of the changes being transplanted, GIT's built-in rename detection may catch that these files are descendants of the files with original names, and simply apply the changes to the original files.

  • If the files got renamed sufficiently far back in the history of release 1.5 (after release 1.0 shipped), GIT will tell you that the files were deleted in release/1.0 because it doesn't know what files in 1.0 correspond to the changes from 1.5.

ANewClass.java will almost certainly trigger the error about having been deleted, unless it was added in one of the changes being back-ported.

Hence, because code might get lost if you blindly follow one set of commands to resolve this situation, that's why GIT prompts you for manual guidance.

查看更多
一纸荒年 Trace。
4楼-- · 2019-03-22 19:39

When all else fails, read the message.

This patch is trying to modify two files, but they have already been deleted; deleting them again did nothing.

Just run git rebase --skip.

查看更多
Evening l夕情丶
5楼-- · 2019-03-22 19:44

do git add -A followed by git rebase --continue. This should add all changes - including your removal of the files and then continue.

There is no guarantee that the commit didn't have other files that did not conflict and should be merged. git rebase --skip would lose those files. You don't want that.

Hope this helps.

查看更多
登录 后发表回答