Last Updated: February 25, 2016
·
413
· mfpiccolo

Drop git changes with a confirm

Drop the following into your ~/.bash_profile and you will be able to use the drop command and you will be prompted to drop all of your changes since the last commit.

# ~/.bash_profile
alias hard_drop="git reset HEAD --hard"
alias drop="confirm && hard_drop"

confirm () {
  # call with a prompt string or use a default
  read -r -p "${1:-Hard reset to last commit? [y/N]} " response
  case $response in
    [yY][eE][sS]|[yY])
      true
      ;;
    *)
      false
      ;;
  esac
}
# example use in terminal
$ drop
> Hard reset to last commit? [y/N]
$ y
> HEAD is now at <commit ref> Some Commit Message