Created
February 3, 2016 19:05
-
-
Save evilchili/c9562987f886b555ff2a to your computer and use it in GitHub Desktop.
bash function to implement a non-destructive git rebase
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
# Like git-rebase -i, but without touching the index or working tree. | |
function git-squash() { | |
if [ "$1" == "" ]; then | |
echo "usage: git-squash <number_of_commits_to_squash>" | |
return | |
fi | |
# note the current HEAD commit | |
old_head=$(git rev-parse HEAD) | |
echo "Current HEAD: $old_head" | |
# http://stackoverflow.com/a/5201642 | |
git reset --soft HEAD~$1 && git commit --edit -m"$(git log --format=%B --reverse HEAD..HEAD@{1})" | |
# print undo action | |
echo | |
echo "To undo this change: git reset $old_head" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment