Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I make git reset --hard safer or disable it?

Tags:

git

git-reset

I have gotten into the bad habit of using git reset --hard regularly.

I now discovered that there is git reset --keep, and if I really need to delete something I could even do git stash && git stash drop.

So I'd like to either disable hard resets, or make them ask before they delete uncommitted changes irrecoverably, or at least create a backup. Can this be done without wrapping git in a shell function?

like image 405
xeruf Avatar asked Nov 09 '25 02:11

xeruf


1 Answers

git does not intrinsically support what you're asking for.

You could write a script or Bash function called git and put that ahead of git in your PATH. The script or function would just check for "forbidden commands" and otherwise run the regular git program (e.g. /usr/bin/git).

like image 165
John Zwinck Avatar answered Nov 11 '25 14:11

John Zwinck



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!