Skip to content

Instantly share code, notes, and snippets.

@eddiemoya
Last active August 5, 2022 15:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eddiemoya/5346242 to your computer and use it in GitHub Desktop.
Save eddiemoya/5346242 to your computer and use it in GitHub Desktop.
Restores file that was deleted in a previous commit based on its last known state before it was removed.
### Git Unremove ##
# Adds an alias called "unrm" to retrieve a pile or path deleted at any point in the repositories history.
# Usage:
# git unrm [path]
# git unrm path/to/file
git config --global alias.unrm '!COMMIT=$(git log -1 --pretty=%h -- "$1"); git checkout $COMMIT^ -- "$1"; echo "File: $1, was restored from commit $COMMIT"; git show -s $COMMIT'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment