Skip to content

Instantly share code, notes, and snippets.

@LongLiveCHIEF
Forked from esebastian/git-amend
Last active May 18, 2022 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LongLiveCHIEF/411ff8af4a7339038fafaa4f51c65364 to your computer and use it in GitHub Desktop.
Save LongLiveCHIEF/411ff8af4a7339038fafaa4f51c65364 to your computer and use it in GitHub Desktop.
Amend the commit message of one specific git commit and rebase to apply the changes
#!/bin/sh
# Amend the commit message one specific commit and rebase
# to apply the changes. Given the SHA hash or a reference
# of the commit to amend, it checkouts the commit, amends
# it interactively and rebases the repo history in current branch.
#
currentbranch=$(git branch --show-current)
if [[ ! -n $1 ]]; then
echo "usage: git amend <SHA>\n"
exit 1
fi
echo "Amending $1..."
git checkout $1 && git commit --amend && git rebase HEAD $currentbranch
[[ $? -eq 0 ]] && echo Done!
[[ $? -ne 0 ]] && echo Error!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment