Created
June 23, 2011 13:42
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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