Skip to content

Instantly share code, notes, and snippets.

@mgamer
Created September 9, 2017 15:59
Show Gist options
  • Save mgamer/3b8f7b0ff782140c480ecd69ef366ab0 to your computer and use it in GitHub Desktop.
Save mgamer/3b8f7b0ff782140c480ecd69ef366ab0 to your computer and use it in GitHub Desktop.
git squash
#!/bin/sh
# based on https://stackoverflow.com/a/24018435/59666
#base commit of the squash-"rebase
baseCommit=$1
#get the commit message
shift
commitMsg=$@
#regular expression to verify that squash number is an integer
regex='^[0-9]+$'
echo "---------------------------------"
echo "Will squash using $baseCommit as base"
echo "Commit message will be '$commitMsg'"
echo "...validating input"
if [ -z "$commitMsg" ]
then
echo "Invalid commit message. Make sure string is not empty"
else
echo "...input looks good"
echo "...proceeding to squash"
git reset --soft $baseCommit
git commit -m "$commitMsg"
echo "...done"
fi
echo
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment