Created
January 29, 2026 20:41
-
-
Save skobes-chromium/7a617a4357d5998abae851a8e8d94ddc 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 | |
| # Sqash all commits in upstream..HEAD to a single commit. | |
| ONTO=$(git rev-parse --abbrev-ref --symbolic-full-name @{u} 2>/dev/null) | |
| if [ -n "$ONTO" ]; then | |
| BEHIND=$(git rev-list --left-right --count $ONTO...@ | cut -f1) | |
| if [ $BEHIND != "0" ]; then | |
| echo "$ONTO: behind $BEHIND" | |
| ONTO= | |
| fi | |
| fi | |
| read -p "Squash from? [$ONTO] " OUT | |
| ONTO=${OUT:-$ONTO} | |
| [ -n "$ONTO" ] || exit 1 | |
| FIRST=$(git rev-list $ONTO.. | tail -1) | |
| [ -n "$FIRST" ] || exit 1 | |
| MSG=$(git show -s --format=%B $FIRST | head -1) | |
| [ -n "$MSG" ] || exit 1 | |
| read -p "Commit message? [$MSG] " OUT | |
| MSG=${OUT:-$MSG} | |
| [ -n "$MSG" ] || exit 1 | |
| echo ">>> git reset --soft $ONTO" | |
| git reset --soft $ONTO | |
| echo ">>> git commit -m \"$MSG\"" | |
| git commit -m "$MSG" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment