0

I made the mistake of merging a hotfix branch with master and then deleting the branch before merging it with develop. Is it possible to recover the hotfix branch so I can do the missed merge? Or would something like a cherry-pick work just the same?

Thanks.

  • `git reflog` is your friend, to see a history of commits you've previously had checked out. Anything still in the reflog hasn't been garbage collected and is still around. – Charles Duffy Jan 18 '19 at 18:54
  • 1
    And yes, if you know the commit, you can cherry-pick *or* merge by commit. – Charles Duffy Jan 18 '19 at 18:55
  • Possible duplicate of [Can I recover a branch after its deletion in Git?](https://stackoverflow.com/questions/3640764/can-i-recover-a-branch-after-its-deletion-in-git) – Charles Duffy Jan 18 '19 at 18:55
  • [Recover deleted branch in git](https://stackoverflow.com/questions/16793637/recover-deleted-branch-in-git) is another pre-answered duplicate (with an answer covering use of `git fsck` to find unreachable commits). – Charles Duffy Jan 18 '19 at 18:56

2 Answers2

1

did you delete the branch only locally ? ie: git branch -d <branch> or globally ie git branch -D <branhc>?

if the branch is still available on remote you can pull it back down, if you deleted it from both local you can go back to the commit in your master branch where you merged in the hotfix and create a new branch from that commit hash git checkout -b <commit hash>

then merge that branch into the develop branch?

dalton
  • 11
  • 1
  • 4
0

The commit should still be available on the machine you deleted the branch from.

If you can remember the commit hash, it's really easy -- just do a git checkout <commit hash>. Then you can point a branch at the commit.

If you don't remember the commit hash, things are a bit more difficult, since you will need to find a dangling commit.

This blog post gives a quick overview on how to do that: http://gitready.com/advanced/2009/01/17/restoring-lost-commits.html

Swiss
  • 5,556
  • 1
  • 28
  • 42