Skip to content

Instantly share code, notes, and snippets.

@ptflp
Last active May 27, 2022 05:25
Show Gist options
  • Save ptflp/5073dcee4047ff78c7c5f1230ea79f20 to your computer and use it in GitHub Desktop.
Save ptflp/5073dcee4047ff78c7c5f1230ea79f20 to your computer and use it in GitHub Desktop.
git squash like automate tool

put to /usr/local/bin/git-squash

execute in bash chmod +x /usr/local/bin/git-squash

use git squash

#!/bin/bash
git log -1
read -p "Enter commit message: " COMMIT
BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [[ `git status --porcelain` ]]; then
git add -A \
&& git commit -m "$BRANCH $COMMIT"
fi
git reset --soft HEAD~$(git cherry -v master | wc -l | xargs) \
&& git stash \
&& git checkout master \
&& git pull \
&& git checkout $BRANCH \
&& git merge master \
&& git stash apply \
&& git add -A \
&& git commit -m "$BRANCH $COMMIT" \
&& git push --set-upstream origin $BRANCH --force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment