Skip to content

Instantly share code, notes, and snippets.

@michaeljklein
Created December 1, 2016 21:51
Show Gist options
  • Save michaeljklein/c0efbaeba7c93cede1c9342c03c2948f to your computer and use it in GitHub Desktop.
Save michaeljklein/c0efbaeba7c93cede1c9342c03c2948f to your computer and use it in GitHub Desktop.
#!/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