]>
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 # if there are local work tree modifications, stash those off leaving 
  27 # the index for amending to the target commit 
  29 if ! git 
diff-files --quiet --ignore-submodules --; then 
  32 test $DIRTY -eq 1 && git stash save 
-q --keep-index git
-amend 
  33 # always restore from stash before exiting 
  34 test $DIRTY -eq 1 && trap 'git stash pop -q stash@{0} 2>/dev/null' EXIT
 
  37 git checkout 
-q "$TARGET" || { 
  38   echo "$(basename $0): changes didn't apply cleanly" 1>&2 
  42 # amend the commit. this opens your editor 
  45 # apply the remaining commits on this branch 
  46 git rebase 
--onto HEAD 
"$TARGET" "$BRANCH"