Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Re-open deleted Git branch

I'm using git flow for my project and I had to make a hotfix branch. When it was completed, I made a pull request to merge it into master and then deleted the branch.

I've since realized that it also needed to be merged into develop. However, I deleted the branch from the remote as well as from my PC. Is there any way I can reopen the branch to make a pull request to merge it to develop?

I'd like to avoid merging master into develop since it also includes other changes that I've made in release branches (bumping version numbers, etc).

Or perhaps there is another, better solution? In general, what is a good practice to use git flow with pull requests?

like image 260
Ben Avatar asked Aug 06 '14 21:08

Ben


People also ask

Can I reopen a closed branch in git?

Under your repository name, click Pull requests. Click Closed to see a list of closed pull requests. In the list of pull requests, click the pull request that's associated with the branch that you want to restore. Near the bottom of the pull request, click Restore branch.

What happens when a git branch is deleted?

What Happens If I Delete a Git Branch? When you delete a branch in Git, you don't delete the commits themselves. That's right: The commits are still there, and you might be able to recover them.


1 Answers

Deleting a branch just removes the label that was attached to the commit. The commit that used to be the head of the branch is still present. You just need to put the label back.

If you merged hotfix into master and it created a merge commit at aabbcc, then you can resurrect hotfix using:

git branch hotfix aabbcc^2

The ^2 is shorthand for "the second parent". If you didn't create a merge commit, then just re-create hotfix using the last of its commits:

git branch hotfix ddeeff

Of course, if you know ddeeff even in the case of a merge commit above, you can use the last commit directly.

like image 105
Greg Hewgill Avatar answered Sep 28 '22 09:09

Greg Hewgill