Skip to content

Instantly share code, notes, and snippets.

@ChrisLahaye
Created October 11, 2024 10:42
Show Gist options
  • Save ChrisLahaye/94c6189ef3ea4d284d4d982b67ff9b7f to your computer and use it in GitHub Desktop.
Save ChrisLahaye/94c6189ef3ea4d284d4d982b67ff9b7f to your computer and use it in GitHub Desktop.
#!/bin/bash -e
#
# git-fixup - creates a fixup commit and squashes it into the given commit using a rebase.
#
# Usage:
# git fixup <commit> [args...]
#
# Options:
# <commit> The commit to "fix up".
# [args...] These arguments are passed verbatim to git-rebase.
if [ "$#" -lt 1 ]; then
awk 'f && !NF { exit } /^#/ && NR>2 { f=1; sub("^# ?", "", $0); print $0 }' < "${BASH_SOURCE[0]}"
exit 1
fi
COMMIT=$(git rev-parse $1)
shift
git commit --fixup=$COMMIT && git -c sequence.editor=: rebase -i --autosquash $COMMIT^ "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment