Recover deleted branch in Git
This question already has an answer here:
Can I recover a branch after its deletion in Git?
- Set parent for first commit on git repository
- Git pushing a branch to remote not working
- Git rebase from one branch to another
- git: track a remote branch not on origin
- How to restrict access to master branch on git
- How to delete specific files & folders from newly created git branch in GITLAB dashboard?
2 Solutions collect form web for “Recover deleted branch in Git”
Create a list of all dangling or unreachable commits.
git fsck --full --no-reflogs --unreachable --lost-found
Print a list of commit messages for all commits in the lost and found.
ls -1 .git/lost-found/commit/ | xargs -n 1 git log -n 1 --pretty=oneline
Find your missing commit through the process of manual inspection (i.e. reading).
Create a new branch with the missing commit as the branch head.
git checkout -b branch-name SHA
Having got the potential sha1 for the last tip of branch
gitk sha1 to actually browse the commit’s history to check you have the right one.