Skip to content

Instantly share code, notes, and snippets.

@adrianotadao
Created July 30, 2015 20:03
Show Gist options
  • Save adrianotadao/a421ae9f627fbe079cd0 to your computer and use it in GitHub Desktop.
Save adrianotadao/a421ae9f627fbe079cd0 to your computer and use it in GitHub Desktop.

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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment