]>
Tony Duckles's Git Repositories (git.nynim.org) - dotfiles.git/blob - bin/git-amend
2 # Usage: git-amend <commit>
3 # Amend changes staged in the index to <commit>, or edit commit message if
4 # no changes are currently staged. Modifications not staged are stashed and
5 # then reapplied once the amend and rebase operations are complete.
7 # This command rewrites history. Do not run it after <commit> or its
8 # decendants have been published to the world.
10 # This version in POSIX sh by Ryan Tomayko <tomayko.com/about>
12 # Based on Mislav's bash version here:
13 # http://gist.github.com/278825
15 # NOTE removed check for staged files, since sometimes I just
16 # want to change the commit message.
19 BRANCH
=$(git name-rev HEAD | cut -d' ' -f2)
21 test -z "$TARGET" && {
22 echo "$(basename $0): you must specify the target commit" 1>&2
26 # stash off work tree modifications leaving the
27 # index for amending to the target commit
28 git stash save
-q --keep-index git
-amend
30 # always restore from stash before exiting
31 trap 'git stash pop -q stash@{git-amend} 2>/dev/null' EXIT
34 git checkout
-q "$TARGET" || {
35 echo "$(basename $0): changes didn't apply cleanly" 1>&2
39 # amend the commit. this opens your editor
42 # apply the remaining commits on this branch
43 git rebase
--onto HEAD
"$TARGET" "$BRANCH"