Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pwpearson/7da8402f3e506d4bb0f6de44f85ea9eb to your computer and use it in GitHub Desktop.
Save pwpearson/7da8402f3e506d4bb0f6de44f85ea9eb to your computer and use it in GitHub Desktop.

Add to .bashrc or .bash_profile

function git_undelete_file () {
  if [ $# -eq 0 ]; then
        echo "Usage: git_undelete_file <filepath>";
        exit 1;
  fi

  git checkout $(git rev-list -n 1 HEAD -- "$1")^ -- "$1"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment