Created
December 5, 2024 09:58
-
-
Save AliYmn/d97459ebcfa676e29fda8a2b7da81391 to your computer and use it in GitHub Desktop.
A safety wrapper for git reset commands that adds a confirmation prompt before executing potentially destructive reset operations. Helps prevent accidental resets while maintaining all original git functionality.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A safety wrapper for git reset commands | |
# Prompts for confirmation before executing potentially destructive reset operations | |
# Usage: Just use git reset or git reset --hard as normal, it will ask for confirmation (y/n) | |
function git() { | |
if [ "$1" = "reset" ]; then | |
if [ "$2" = "--hard" ]; then | |
echo -n "Are you sure you want to execute 'git reset --hard'? (y/n): " | |
read REPLY | |
if [[ $REPLY =~ ^[Yy]$ ]]; then | |
command git "$@" | |
else | |
echo "Operation cancelled." | |
fi | |
elif [ "$#" = 1 ] || [ "$2" != "--soft" -a "$2" != "--mixed" -a "$2" != "--merge" -a "$2" != "--keep" ]; then | |
echo -n "Are you sure you want to execute 'git reset'? (y/n): " | |
read REPLY | |
if [[ $REPLY =~ ^[Yy]$ ]]; then | |
command git "$@" | |
else | |
echo "Operation cancelled." | |
fi | |
else | |
command git "$@" | |
fi | |
else | |
command git "$@" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment