Bash protection against "git reset --hard HEAD"
If you ever execute git reset --hard HEAD
on a unstaged and uncommited repository, be prepared to loose everything up to your last commit. If you code has been staged, git reflog
or git fsck
may save you, but, still, you're about to have a lot of trouble to find your files.
This is a an alias script, intended to ask you a question before deleting your work. Create a file and source this on bash:
git() {
if [[ "$1" = "reset" ]] && [ "$2" = "--hard" ] && [ "$3" = "HEAD" ] ; then
echo "are you being a moron again? (yes/no)"
read i
if [ "$i" != "no" ]; then
echo "you're safe, reset not executed"
return 0
fi
fi
command git "$@"
}
Written by Antonio Ribeiro
Related protips
2 Responses
Got any background articles on why it's bad to use git reset --hard HEAD
?
over 1 year ago
·
Protip edited to give some background info on why is this so scaring...
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Git
Authors
khasinski
591.1K
dmichaelavila
500.4K
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#