threads / bug / 40368

Bug after removing a local branch and restore the remote branch during a rebase

Subject: Bug after removing a local branch and restore the remote branch during a rebase

## tl;dr

2 messages between Sep 17, 2015 and Sep 17, 2015.

replies: 1people: 2as markdown or json

Robert Strobl· Sep 17, 2015, 10:12 UTC · lore
It might be an unusual workflow, however it leads to a bug:

git checkout feature_branch git rebase master

# a couple of conflicts occur, which I don’t want to fix. there is an updated version on origin # so I’d like to go with that one

git add . git stash git checkout master git branch -D feature_branch git pull git checkout feature_branch git status

# On branch feature_branch # You are currently rebasing branch ‘feature_branch' on '195269d'. # (all conflicts fixed: run "git rebase --continue")

# nothing to commit, working directory clean
# It still thinks that I’m rebasing the branch, so let’s try:
git rebase —abort

# On branch feature_branch # Your branch and ‘origin/feature_branch' have diverged, # and have 104 and 77 different commits each, respectively. # (use "git pull" to merge the remote branch into yours) # nothing to commit, working directory clean

I’m aware that I should have aborted the rebase and then fetch the remote branch. However, I still think that when I delete a local branch, it should also abort the rebase that is attached to it.

I hope you find that useful. If it makes sense, I would be happy writing a patch for it :)

Cheers, Robert

Jacob Keller· Sep 17, 2015, 16:44 UTC · re: Robert Strobl · lore

Re: Bug after removing a local branch and restore the remote branch during a rebase

Hi,

On Thu, Sep 17, 2015 at 3:12 AM, Robert Strobl <robert.strobl@surialabs.com> wrote:

Show 5 quoted lines
> It might be an unusual workflow, however it leads to a bug:
>
> git checkout feature_branch
> git rebase master
>
Ok so you are performing the rebase...
Show 11 quoted lines
> # a couple of conflicts occur, which I don’t want to fix. there is an updated version on origin
> # so I’d like to go with that one
>
> git add .
> git stash
> git checkout master
> git branch -D feature_branch
> git pull
> git checkout feature_branch
> git status
>

So you delete the branch, but the rebase stores the branch it's working on by name, *and* you then re-create the branch again by "git checkout feature_branch"

Show 7 quoted lines
> # On branch feature_branch
> # You are currently rebasing branch ‘feature_branch' on '195269d'.
> #  (all conflicts fixed: run "git rebase --continue")
>
> # nothing to commit, working directory clean
>
> # It still thinks that I’m rebasing the branch, so let’s try:
You are still rebasing.
Show 12 quoted lines
>
> git rebase —abort
>
> # On branch feature_branch
> # Your branch and ‘origin/feature_branch' have diverged,
> # and have 104 and 77 different commits each, respectively.
> #  (use "git pull" to merge the remote branch into yours)
> # nothing to commit, working directory clean
>
> I’m aware that I should have aborted the rebase and then fetch the remote branch.
> However, I still think that when I delete a local branch, it should also abort the rebase that is attached to it.
>

So what happened here is the rebase --abort tries to return you to the starting situation when you began the rebase. Normally if you change the current checked out branch to a new one, ie: git checkout master, it will say "not returning to ORIG_HEAD"... however... you are on the same branch name, thus rebase --abort returns you to your position.

> I hope you find that useful. If it makes sense, I would be happy writing a patch for it :)
>

I don't think anything needs to happen. You admit that you should have run "git rebase --abort" first. Second, you actually re-create the same branch name again...

After fixing up the rebase --abort, just perform a git reset to fix your tree where you want it.

In fact I prefer current behavior which has lower risk of lost work, since abort puts you back to where you were before... I don't think that supporting "I deleted a branch" makes sense here.

a) there is an easy known practice for this flow... rebase --abort first
b) there is an easy fix after you rebase --abort late: git reset --hard master

Between these two things I don't think we should change rebase to stop recovering the history.

Regards, Jake

> Cheers,
> Robert--

← back to recent threads