{"thread":{"id":"40368","subject":"Bug after removing a local branch and restore the remote branch during a rebase","startedAt":"2015-09-17T10:12:14Z","lastAt":"2015-09-17T16:44:12Z","messageCount":2,"participants":["Robert Strobl","Jacob Keller"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"270200","messageId":"CF93B86B-8CCF-483D-918A-47C910CEE8BA@surialabs.com","threadId":"40368","inReplyTo":null,"subject":"Bug after removing a local branch and restore the remote branch during a rebase","fromName":"Robert Strobl","fromEmail":"robert.strobl@surialabs.com","sentAt":"2015-09-17T10:12:14Z","receivedAt":"2015-09-17T10:12:14Z","isPatch":false,"sender":{"key":"robert.strobl@surialabs.com","avatar":null},"body":"It might be an unusual workflow, however it leads to a bug:\n\ngit checkout feature_branch\ngit rebase master\n\n# a couple of conflicts occur, which I don’t want to fix. there is an updated version on origin\n# so I’d like to go with that one\n\ngit add .\ngit stash\ngit checkout master\ngit branch -D feature_branch\ngit pull\ngit checkout feature_branch\ngit status\n\n# On branch feature_branch\n# You are currently rebasing branch ‘feature_branch' on '195269d'.\n#  (all conflicts fixed: run \"git rebase --continue\")\n\n# nothing to commit, working directory clean\n\n# It still thinks that I’m rebasing the branch, so let’s try:\n\ngit rebase —abort\n\n# On branch feature_branch\n# Your branch and ‘origin/feature_branch' have diverged,\n# and have 104 and 77 different commits each, respectively.\n#  (use \"git pull\" to merge the remote branch into yours)\n# nothing to commit, working directory clean\n\nI’m aware that I should have aborted the rebase and then fetch the remote branch.\nHowever, I still think that when I delete a local branch, it should also abort the rebase that is attached to it.\n\nI hope you find that useful. If it makes sense, I would be happy writing a patch for it :)\n\nCheers,\nRobert"},{"id":"270230","messageId":"CA+P7+xpKQasAQ3Qx4bbQWX7N4kQqknKGW7Xei6xCNEY=p7CraA@mail.gmail.com","threadId":"40368","inReplyTo":"CF93B86B-8CCF-483D-918A-47C910CEE8BA@surialabs.com","subject":"Re: Bug after removing a local branch and restore the remote branch during a rebase","fromName":"Jacob Keller","fromEmail":"jacob.keller@gmail.com","sentAt":"2015-09-17T16:44:12Z","receivedAt":"2015-09-17T16:44:12Z","isPatch":false,"sender":{"key":"jacob.keller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"Hi,\n\nOn Thu, Sep 17, 2015 at 3:12 AM, Robert Strobl\n<robert.strobl@surialabs.com> wrote:\n> It might be an unusual workflow, however it leads to a bug:\n>\n> git checkout feature_branch\n> git rebase master\n>\n\nOk so you are performing the rebase...\n\n> # a couple of conflicts occur, which I don’t want to fix. there is an updated version on origin\n> # so I’d like to go with that one\n>\n> git add .\n> git stash\n> git checkout master\n> git branch -D feature_branch\n> git pull\n> git checkout feature_branch\n> git status\n>\n\nSo you delete the branch, but the rebase stores the branch it's\nworking on by name, *and* you then re-create the branch again by \"git\ncheckout feature_branch\"\n\n> # On branch feature_branch\n> # You are currently rebasing branch ‘feature_branch' on '195269d'.\n> #  (all conflicts fixed: run \"git rebase --continue\")\n>\n> # nothing to commit, working directory clean\n>\n> # It still thinks that I’m rebasing the branch, so let’s try:\n\n\nYou are still rebasing.\n\n>\n> git rebase —abort\n>\n> # On branch feature_branch\n> # Your branch and ‘origin/feature_branch' have diverged,\n> # and have 104 and 77 different commits each, respectively.\n> #  (use \"git pull\" to merge the remote branch into yours)\n> # nothing to commit, working directory clean\n>\n> I’m aware that I should have aborted the rebase and then fetch the remote branch.\n> However, I still think that when I delete a local branch, it should also abort the rebase that is attached to it.\n>\n\nSo what happened here is the rebase --abort tries to return you to the\nstarting situation when you began the rebase. Normally if you change\nthe current checked out branch to a new one, ie: git checkout master,\nit will say \"not returning to ORIG_HEAD\"... however... you are on the\nsame branch name, thus rebase --abort returns you to your position.\n\n> I hope you find that useful. If it makes sense, I would be happy writing a patch for it :)\n>\n\nI don't think anything needs to happen. You admit that you should have\nrun \"git rebase --abort\" first. Second, you actually re-create the\nsame branch name again...\n\nAfter fixing up the rebase --abort, just perform a git reset to fix\nyour tree where you want it.\n\nIn fact I prefer current behavior which has lower risk of lost work,\nsince abort puts you back to where you were before... I don't think\nthat supporting \"I deleted a branch\" makes sense here.\n\na) there is an easy known practice for this flow... rebase --abort first\n\nb) there is an easy fix after you rebase --abort late: git reset --hard master\n\nBetween these two things I don't think we should change rebase to stop\nrecovering the history.\n\nRegards,\nJake\n\n> Cheers,\n> Robert--\n"}]}