Unintentional Branch deletions from Merge with conflicts (BB-11083)

Issue #10242 resolved
Alexis Barrera created an issue

I can consistently reproduce the following bug:

I navigate to a branch in a bitbucket repository and click on merge, selecting the "close branch" option. I get a merge conflict (because of a submodule change) and I click cancel (but leave the close branch checkbox selected).

Instead of merely canceling the merge, Bitbucket deletes my branch, even though the merge failed.

I came close a couple of times to losing work, so this is pretty bad. This branch shouldn't have been deleted, for example: https://bitbucket.org/idg-dev/misc/branch/CORE-589

Official response

Comments (40)

  1. Alexis Barrera reporter

    Great! Thank you. I've tried it a few more times on our other repos and same deal, if that helps =)

  2. Brendon McCarthy

    Same issue, except the merge cancelled on its own due to Merge conflict that could not be resolved automatically. The branch was closed, but the commit remains. After Bitbucket cancelled the merge, deleted the branch, landing on the "compare" page, with an orphaned commit comparison to master, but no changes detected. @Alexis, how did you end up resolving the issue?

  3. Luis Faceira

    I've also experienced in first-hand this problem and I consider it to be a very serious issue that should be addressed with much urgency.

    If the local copy of a branch is deleted (which is something we periodically do after making sure it's published on bitbucket), then this would make us loose all the work that has been done on that branch, which can mean several hours or days of work down the drain.

    Can't the conflicts be proactively detected and the merge button simply not being enabled, such as what happens on pull requests?

    I'm a paying user of the service with several private repositories and I consider this to be urgent to be fixed.

  4. Alexis Barrera reporter

    @bmccarthy_hp I'm still seeing this problem ... but after bravely testing it a few times I think the problem is mostly a UI/Experience issue.

    Basically, this only happens to us on a branch that has already been merged. It seems like the error is more along the lines of can't/don't need to remerge. We should be getting an info message or something, not an error.

  5. Brendon McCarthy

    In the most simple form, the branch should not be deleted (closed) if a merge conflict causes the merge to fail. Technically if the branch is not actually being deleted (?) and is a UI issue, we need to be able to see and manage the branch (both from Bitbucket) and from a Git client.

    We were able to recover using the local branch that still existed and re-commit/push to a new branch (but like @luisfaceira said is not always an option). As it works now, we cannot use Bitbucket UI to merge as we cannot predict what it will do if there is a merge conflict.

  6. Luis Faceira

    I disagree with @mesolimbo that this is mostly a UI issue. From our experience this does NOT only happen on branches that have already been merged, if that was true, I would agree that this is not such a serious issue.

    But it happens with ALL branches that cannot be merged, either because they've already been merged but also because they have conflicts to be resolved. Since it deletes the origin branch, unless we are lucky to still have the original branch locally, there's no branch for us to solve the conflicts, because such branch was deleted!

  7. Alexis Barrera reporter

    Fair enough, we only ever test the feature on merged branches so I can't vouch for it ever working safely.

  8. Yeen Fei Lim

    please advise what can be done when facing this issue ?!? our feature branch got deleted after an unsuccessful merge, and the origin branch got killed !?! cant believe such important flaw still exist after 6months+...

  9. Davide Balistreri

    Hi all, today I lost two months of committed work on a deleted branch after a failed fast-forward merge issued from the Bitbucket UI. After spending some hours I couldn't recover anything even by using Git through the terminal, but "fortunately" Bitbucket shows some last commits of the lost branch in the recent activity RSS in the Overview of my project. I will try to checkout the last-lost-commit with his identifier, and copy all changed code since the last commit on my master branch. This is unbelievable...

  10. Davide Balistreri

    Hi Alexis, I managed to get access to the original .git folder and then reset the HEAD pointer to the last commit before the failed merge. Then I forced a push towards Bitbucket repository and all the lost work became available again. Thank you for your support!

  11. Alexis Barrera reporter

    Oh good, I'm glad you got your bits back =)

    FYI, now's the perfect time to set-up a cronjob on a quiet server to do a git pull every 15 mins ... that way you give yourself a 15 minute failure recovery window should anything odd happen in your repo.

  12. Michael B

    For bonus points, you can have your cronjob record changes so you can easily recover from force pushes that you wish never had happened...if you catch them early they aren't so bad.

  13. Former user Account Deleted

    Came across this issue today and pretty shocked to see it has been open for so long. Are there any plans to fix it?

  14. Michael O'Callaghan

    I also too became a victim of this. I am new to BB but I have to say is there anyway back to recovering the removed branch that was deleted even though it failed due to conflicts? It does mean I have to scramble to local copies which I will be able to do so but just as I was starting to feel confident with the web browser merge tools . . . @Atlassian can you jump in regarding this please?

  15. Jozef Spisiak

    I just lost couple of pull requests due to this (luckily had a local backup of my work). Please, this is really blocker or at least remove the functionality to close branch if that is causing the branch to be deleted (not sure if it can happen if it is not checked).

  16. Fraser Hardy

    I've just had the same thing happen. The PR wasnt actually showing conflicts, clicked merge with Delete branch ticked. The merge then failed due to conflicts but my branch deleted. The PR still showed the changes but I was unable to access the original branch, and couldnt get latest changes by git pull either with error

    git -c diff.mnemonicprefix=false -c core.quotepath=false -c credential.helper=sourcetree pull --log origin feature/QSERVER-2608_Integrations-set-up-page 
    fatal: Couldn't find remote ref feature/QSERVER-2608_Integrations-set-up-page
    Completed with errors, see above

    I had to contact the original developer who luckily still had it on his local. This needs an urgent fix!!

  17. Michael Sagalovich

    Maybe it even makes sense to remove the "Delete branch" tickbox until the issue is resolved?

  18. Alexis Barrera reporter

    Two years ... I can't believe Atlassian still hasn't fixed this issue! Good luck folks, I've long since moved over to Github.

  19. Jens Zalzala

    I just lost a lot of costly work due to this bug, and I don't have a local copy, and the person who committed the code doesn't work here anymore. Like others have mentioned, I can still see the commit, but I can't figure out how to check it out or do anything with it. it's too big to show me all the details. If anyone has found a way to recover their lost work, please share. The close branch checkbox needs to be removed until this bug is fixed.

  20. Jonathan Robson staff

    Hello, all. Sorry for the delay in fixing this, but it should now be fixed. Let us know if you're still experiencing this issue.

  21. Log in to comment