Last active
December 14, 2015 05:59
-
-
Save kyamaguchi/548d8b03880251f6827a to your computer and use it in GitHub Desktop.
git fixup
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/bash | |
# https://github.com/deiwin/git-dotfiles/blob/docs/bin/git-fixup | |
set -e | |
# Get the reference to the commit before creating the fixup commit, | |
# because, say, if the argument is relative to the HEAD then the | |
# commit it refers to will change once we create a new commit on the | |
# HEAD. | |
COMMIT_TO_BE_FIXED=`git show --format=%H --no-patch $1` | |
git commit --fixup=$COMMIT_TO_BE_FIXED | |
# Stash unstaged changes (the staged changes will already be in the | |
# commit created above) to avoid not being able to run the rebase | |
# command. | |
if [[ -n $(git status -s | grep -v '??') ]] | |
then | |
git stash | |
HAS_STASHED_CHANGES=true | |
fi | |
GIT_SEQUENCE_EDITOR='true' git rebase --interactive --autosquash $COMMIT_TO_BE_FIXED~ | |
if [[ -n "$HAS_STASHED_CHANGES" ]] | |
then | |
git stash pop | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added
grep -v '??'
to fix unnecessarystash pop
when index and stage are clean and untrack files exist.