Skip to content

Instantly share code, notes, and snippets.

@CrCs2O4
Created July 26, 2017 10:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CrCs2O4/e3bf55c558ba5dc3ebb93908a3bf8fea to your computer and use it in GitHub Desktop.
Save CrCs2O4/e3bf55c558ba5dc3ebb93908a3bf8fea to your computer and use it in GitHub Desktop.
fsck --lost-found | grep commit | cut -d ' ' -f 3 | xargs -n 1 git log -n 1 --pretty=oneline
## Pre-requisite: You have to know your last commit message from your deleted branch.
git reflog
# Search for message in the list
# a901eda HEAD@{18}: commit: <last commit message>
# Now you have two options, either checkout revision or HEAD
git checkout a901eda
# Or
git checkout HEAD@{18}
# Create branch
git branch recovered-branch
# You may want to push that back to remote
git push origin recovered-branch:recovered-branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment