Skip to content

Instantly share code, notes, and snippets.

@MacroMan
Last active January 31, 2024 14:20
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 MacroMan/01f9b1d0f808c19570ca4055ca8e83b9 to your computer and use it in GitHub Desktop.
Save MacroMan/01f9b1d0f808c19570ca4055ca8e83b9 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Auto squash commits down into one prior commit
# Usage:
# ./git-squash.sh n
# where n is the total number of commits to squash (excluding the commit to remain)
squashCount=$1
echo "Squash the following commits:"
git log --no-decorate --format=oneline --max-count=$squashCount
echo "into:"
git log --no-decorate --format=oneline --max-count=1 --skip=$squashCount
read -n1 -s -r -p $'Press any key to continue or [Crtl-c] to exit\n'
git stash
git reset --soft HEAD~$squashCount
git commit --all --amend --no-edit
git stash pop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment