Created
August 27, 2015 08:48
-
-
Save therealbnut/2cbef756cae217297b0f to your computer and use it in GitHub Desktop.
Swaps the last two commits, perhaps, who knows? Have fun!
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
[alias] | |
swap-last-two-commits = "!f() {\n\ | |
set -eu \n\ | |
if [ ! -z \"`git diff HEAD`\" ]; then \n\ | |
echo \"Found uncommited changes... exiting.\" 1>&2 \n\ | |
exit 1 \n\ | |
fi \n\ | |
HEAD_0=\"$(git rev-parse --verify HEAD)\" \n\ | |
HEAD_1=\"$(git rev-parse --verify HEAD~1)\" \n\ | |
echo \"swapping ${HEAD_0} and ${HEAD_1}\" \n\ | |
git reset --soft HEAD~2 \n\ | |
git commit -C \"${HEAD_1}\" 1> /dev/null \n\ | |
HEAD_0_1=\"$(git rev-parse --verify HEAD)\" \n\ | |
git reset --hard HEAD~1 1> /dev/null \n\ | |
git cherry-pick \"${HEAD_0}\" 1> /dev/null \n\ | |
git cherry-pick --strategy=recursive -X theirs \"${HEAD_0_1}\" 1> /dev/null \n\ | |
if [ ! -z \"`git diff \"${HEAD_0}\"`\" ]; then \n\ | |
echo \"HEAD differs from \"${HEAD_0}\" run 'git reset --hard \"${HEAD_0}\"' to undo. \" 1>&2 \n\ | |
exit 1 \n\ | |
fi \n\ | |
}; f" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment