Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prompt for confirmation before executing "git reset --hard" [duplicate]

Tags:

git

Unstaged, uncommitted changes are lost after running "git reset --hard HEAD". Can I configure git to ask for confirmation before running this (potentially destructive) command?

like image 371
tba Avatar asked Feb 20 '26 09:02

tba


1 Answers

put

git() {
    if [ "$1" = "rebase" ] && [ "$2" = "--hard" ] && [ "$3" = "HEAD" ] ; then
        echo "are you being a moron again?"
        read i
        if [ "$i" = "no" ]; then
             command git $@
        fi
     fi
}

in your ${HOME}/.profile

Update: while this is one way to solve the problem, I prefer to make a branch backup when I am not entirely confident about the history rewriting operation I'm about to do. I achieve the backup by either force purshing to a WIP branch on remote or using git-branch-backup

like image 80
Jan Matějka Avatar answered Feb 22 '26 21:02

Jan Matějka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!