Last active
August 26, 2020 17:58
-
-
Save mjambon/119b04bf2df4d37609c80aeb93a1100f to your computer and use it in GitHub Desktop.
Delete a commit from a git branch
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
#! /usr/bin/env bash | |
# | |
# Remove a single git commit from history. | |
# | |
set -eu | |
usage() { | |
cat <<EOF | |
Usage: $0 <commit ID> | |
Remove the specified git commit, rewriting the history of the branch from | |
that point. | |
It is recommended you try this on a new branch first e.g. | |
git checkout -b practice | |
git-delete 6b2484a | |
# then check the code you wanted gone | |
EOF | |
} | |
if [[ $# != 1 ]]; then | |
usage | |
exit 1 | |
fi | |
commit=$1 | |
set -x | |
git rebase --rebase-merges --onto "$commit"^ "$commit" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment