8

Help! I need to recover a branch. I've been using git with the Bitbucket UI to try and simplify things, but missed a checked checkbox...

What I did:

I created a pull request and merged my feature branch into the dev branch, closing the feature branch (desired outcome).

I then created a pull request and merged my dev branch into the staging branch (desired), but I missed that the checkbox was still marked to "close branch on merge", which happened (not desired).

What I want:

I would like to roll back the merge so that I have a dev branch with the feature branch merged into it (with all its commit history, etc). I don't care if the staging branch is dev-branch-less, or not, I don't mind creating the pull request and merging them correctly again if necessary. Is it possible to recover the dev branch with its history now that it has been closed?

Austerly
  • 83
  • 1
  • 4

2 Answers2

3

Is it possible to recover the dev branch with its history now that it has been closed?

If you still have the branch locally - simply use it, push the local branches to the remote and merge the feature branch into it if you need to.


In case you don't have any of those branches.

What to do?

Read this answer and learn how to use reflog to recover your branches. [How to move HEAD back to a previous location? (Detached head)

Another option is to checkout the merged branch and to split it into the desired commits using the checkout command - again full details in the above answer.

Another option is to checkout the base branch and use cherry-pick to select the range of commits you need.

Community
  • 1
  • 1
CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • Thank you @codeWizard! I was able to use `git reset` referenced above to bring my local `dev` branch up to date, and then pushed it to the repo, which restored all the back references to previous commits as well. – Austerly Feb 18 '16 at 20:51
  • Cool, if the second answer helped you out please be kind enough to vote for it as well. im spending a lot of time writing good and detailed answer so users can solve thier problems and learn new materials as well. Thank you very much for the support. – CodeWizard Feb 18 '16 at 20:56
2

All you need to do is push the dev branch from local machine and it will create a new origin/dev branch on BitBucket. No need to create a new pull request.

tejasbubane
  • 914
  • 1
  • 8
  • 11