Last active
April 16, 2026 09:47
-
-
Save MacroMan/01f9b1d0f808c19570ca4055ca8e83b9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/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' | |
| stash_output=$(git stash) | |
| git reset --soft HEAD~$squashCount | |
| git commit --all --amend --no-edit | |
| [[ "$stash_output" != "No local changes to save" ]] && git stash pop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment