Created
May 13, 2024 15:10
-
-
Save jtzero/66128357267126dd4bf9e9b7ffd68dd5 to your computer and use it in GitHub Desktop.
This file contains 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 | |
set -Eeuo pipefail | |
COMMIT_SHA="${1:-}" | |
printerr() { printf "\033[0;31m%s\033[0m\n" "$@" >&2; } | |
usage() { | |
# shellcheck disable=SC2016 | |
printerr 'usage: git-autosquash $COMMIT_SHA | |
COMMIT_SHA defaults to a "fixup!"~1 commit | |
use '\''git commit --fixup $COMMIT_SHA'\'' before running' | |
} | |
if [ -z "${COMMIT_SHA}" ]; then | |
usage | |
exit 2 | |
else | |
if [ "$(git rev-list --abbrev-commit --max-parents=0 HEAD)" = "${COMMIT_SHA}" ]; then | |
GIT_SEQUENCE_EDITOR=: git rebase -i --root --autosquash | |
else | |
GIT_SEQUENCE_EDITOR=: git rebase -i --autosquash "${COMMIT_SHA}~1" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment