Skip to content

Instantly share code, notes, and snippets.

@ricardoaugusto
Created November 4, 2022 18:27
Show Gist options
  • Save ricardoaugusto/4c4ca52294073be6b066c28b8e410c51 to your computer and use it in GitHub Desktop.
Save ricardoaugusto/4c4ca52294073be6b066c28b8e410c51 to your computer and use it in GitHub Desktop.
Resets a commit and push --force
#!/bin/bash
# usage: sh git-reset.sh -h someCommitHash -t some/feature-branch
while getopts h:t: flag
do
case "${flag}" in
h) hashed=${OPTARG};;
t) target=${OPTARG};;
esac
done
if [$hashed === '']
then
hashed=$(git rev-parse --short HEAD)
fi
if [$target === '']
then
target=$(git symbolic-ref --short HEAD)
fi
git reset --hard $hashed
git push origin $target --force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment