Why does rebasing unset my current branch and does not complete?

98 views Asked by At

I'm on branch b4 and do "$ git rebase master", it gives me conflicts.

 $ git rebase master
    First, rewinding head to replay your work on top of it...
    Applying: rebase: Modified 1.txt
    Using index info to reconstruct a base tree...
    M       1.txt
    Falling back to patching base and 3-way merge...
    Auto-merging 1.txt
    CONFLICT (content): Merge conflict in 1.txt
    Failed to merge in the changes.
    Patch failed at 0001 rebase: Modified 1.txt
    The copy of the patch that failed is found in:
       c:/hands_on/github/learn_git/cmd/.git/rebase-apply/patch

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

Here, it shows that I'm NO longer on branch b4.

 $ git status
    # Not currently on any branch.
    # You are currently rebasing.
    #   (fix conflicts and then run "git rebase --continue")
    #   (use "git rebase --skip" to skip this patch)
    #   (use "git rebase --abort" to check out the original branch)
    #
    # Unmerged paths:
    #   (use "git reset HEAD <file>..." to unstage)
    #   (use "git add <file>..." to mark resolution)
    #
    #       both modified:      1.txt
    #
    no changes added to commit (use "git add" and/or "git commit -a")

I fixed conflicts and committed the changes:

$ vim 1.txt

$ git commit -a -m "Fixed rebase conflict"
[detached HEAD 2cb2672] Fixed rebase conflict
 1 file changed, 1 insertion(+)

$ git status
# Not currently on any branch.
# You are currently rebasing.
#   (all conflicts fixed: run "git rebase --continue")
#
nothing to commit, working directory clean

But when I tried "--continue", it does not complete rebase, but instead giving me more "instructions". Why?

$ git rebase --continue
Applying: rebase: Modified 1.txt
No changes - did you forget to use '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".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".
1

There are 1 answers

0
AudioBubble On BEST ANSWER

I fixed conflicts and committed the changes:

That's where you went wrong. git rebase --continue expects the changes to be in the index, but not yet committed. Since you already committed the changes, git rebase's own attempt fails, because there are no changes left to be committed.

You should be able to undo your commit action, without resetting the index, by running git reset --soft @^. And git rebase --continue should work after that.

You could alternatively use git rebase --skip to bypass git rebase's own attempt to commit the changes, but this risks a bit more getting messed up: your own commit will most likely not have respected the original commit's author name, email and time.

The fact that git status shows you're not on any branch is not a problem. git rebase intentionally detaches from the current branch until the operation finishes. This will be fixed up after the operations have succeeded.