I pushed my branch to the gitlab and then deleted my local branch but someone deleted remote branch by mistake is there any way to recover my branch
Asked
Active
Viewed 1,419 times
1 Answers
5
- If you just deleted the branch, you'll see something like this in your
Deleted branch <your-branch> (was <sha>)
To restore the branch, use:
git checkout -b <branch> <sha>
- If you don't know the 'sha' off the top of your head, you can:
Find the 'sha' for the commit at the tip of your deleted branch using:
git reflog
To restore the branch, use:
git checkout -b <branch> <sha>
- If your commits are not in your reflog:
You can try recovering a branch by reseting your branch to the sha of the commit found using a command like:
git fsck --full --no-reflogs --unreachable --lost-found | grep commit | cut -d\ -f3 | xargs -n 1 git log -n 1 --pretty=oneline > .git/lost-found.txt
You can then display each commit using one of these:
git log -p <commit>
git cat-file -p <commit>

spike 王建
- 1,556
- 5
- 14