Skip to content

Instantly share code, notes, and snippets.

@jarryDk
Created November 4, 2019 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jarryDk/33b2a8ed11949ff4b96d35d504ceccad to your computer and use it in GitHub Desktop.
Save jarryDk/33b2a8ed11949ff4b96d35d504ceccad to your computer and use it in GitHub Desktop.
Do git squash
#!/bin/bash
function gitSquash() {
# Check if the current directory is in a Git repository.
if [ "$(git rev-parse --is-inside-work-tree &>/dev/null; echo "${?}")" == '0' ]; then
if [ "X" != "X$1" ]; then
MESSAGE=""
if [ "X" != "X$2" ]; then
MESSAGE=" -m \"$2\""
fi
command="git reset --soft HEAD~$1"
$command
command="git commit$MESSAGE"
$command
else
echo "Head is first argument"
fi
else
echo "Current directory is NOT in a Git repository"
fi
}
alias gitS=gitSquash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment