Skip to content

Instantly share code, notes, and snippets.

@chadwhitacre
Last active February 24, 2021 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chadwhitacre/5d2ff5f46cd0bc981b3f3b76cf891b97 to your computer and use it in GitHub Desktop.
Save chadwhitacre/5d2ff5f46cd0bc981b3f3b76cf891b97 to your computer and use it in GitHub Desktop.
sq - squash git commits easily
#!/usr/bin/env zsh
#
# https://gist.github.com/chadwhitacre/5d2ff5f46cd0bc981b3f3b76cf891b97
#
# Squash the N most recent git commits together (default: 2), using the oldest
# one's commit message.
N=${1:-2}
msg="$(git log --format=%B -n 1 HEAD~$(( $N - 1 )))"
git reset --soft HEAD~$N && git commit -nm "$msg"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment