Created
December 1, 2016 21:51
-
-
Save michaeljklein/c0efbaeba7c93cede1c9342c03c2948f to your computer and use it in GitHub Desktop.
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 | |
# To squash the last three commits: git squash 3 | |
# It will open an interactive editor so you can | |
# more easily combine the comments | |
source "$(git --exec-path)/git-sh-setup" | |
USAGE="COMMITS" | |
function _squash() { | |
if [[ $# == 1 ]]; then | |
if [[ -n $(git rev-parse --verify --quiet HEAD~$1) ]]; then | |
git reset --soft HEAD~$1 && | |
git commit --edit -m"$(git log --format=%B --reverse HEAD..HEAD@{1})" | |
else | |
die "HEAD~$1 does not exist" | |
fi | |
else | |
usage | |
fi | |
} | |
_squash $1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment