Skip to content

Instantly share code, notes, and snippets.

@jdelStrother
Created June 23, 2011 13:42
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdelStrother/1042552 to your computer and use it in GitHub Desktop.
Save jdelStrother/1042552 to your computer and use it in GitHub Desktop.
Auto-fixup a previous git commit with the changes from your staging area
#!/bin/sh
# Auto-applies changes from the index to a previous commit
# eg
# git add foo
# git autofix HEAD~3
#!/bin/sh
target="$(git rev-parse $1)"
if ! git commit --fixup=$target ; then
echo "commit fail, aborting"
exit 1
fi
dirty="$(git diff --name-only --exit-code HEAD)"
( test -z "$dirty" || git stash ) &&
GIT_EDITOR=cat git rebase --interactive --autosquash $target~1 &&
( test -z "$dirty" || git stash pop )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment