The Script
#!/bin/bash
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
COMMIT_MESSAGE=$1
FROM_BRANCH=${2-develop}
MERGE_BASE_ID=$(git merge-base HEAD $FROM_BRANCH)
echo -e "$(tput setaf 2)** Executing reset command$(tput sgr0)"
git reset --soft $MERGE_BASE_ID
echo -e "$(tput setaf 2)\n** Executing add command$(tput sgr0)\n"
git add .
echo -e "$(tput setaf 2)\n** Executing commit command$(tput sgr0)\n"
git commit -m "$COMMIT_MESSAGE"
echo -e "$(tput setaf 2)\n** Executing push command$(tput sgr0)\n"
git push origin -f $CURRENT_BRANCH
Instalation
sudo vim /bin/git-squash
- past the script and save the file
sudo chmod +x /bin/git-squash
To execute:
At some git repository, run:
git squash "Commit Message"
or
git-squash "Commit Message"