Created
May 6, 2011 04:52
-
-
Save ConradIrwin/958458 to your computer and use it in GitHub Desktop.
git-uncommit
This file contains hidden or 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 | |
# Git uncommit allows you to remove changes from your previous commit, | |
# without loosing any unstaged changes you may have. | |
# When called with no arguments, removes the entire commit (git reset HEAD^) | |
# When called with <filename>, removes changes to that file from the commit. | |
# Also useful is git uncommit -p, which allows you to select which chunks to uncommit. | |
# | |
if [ "$#" = 0 ]; then | |
git reset HEAD^ | |
else | |
[ "$(git stash)" = "No local changes to save" ] | |
stash_failed=$? | |
git checkout HEAD^ "$@" | |
git commit -a --amend -C HEAD | |
[ $stash_failed = 0 ] || git stash pop | |
git apply <(git diff HEAD HEAD@{1}) | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment