Skip to content

Instantly share code, notes, and snippets.

@smootoo
Created May 31, 2016 16:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smootoo/333c21c956b92679f0a2bcd80dd69d11 to your computer and use it in GitHub Desktop.
Save smootoo/333c21c956b92679f0a2bcd80dd69d11 to your computer and use it in GitHub Desktop.
script to interactively git rebase commits that have a single character '.' as the commit message
#!/bin/bash
# script to interactively git rebase commits that have a single character '.' as the commit message
# onto the first commit that isn't just a '.'
squashLine=$(git log --oneline | grep -n -m 1 --perl-regexp "^[\da-f]*\s[^.]")
lineNumber=$(echo ${squashLine} | cut -d : -f 1)
if (( lineNumber >= 2 )); then
squashTo=$(echo ${squashLine} | cut -d : -f 2)
echo "Squish ${lineNumber} commits onto ${squashTo}"
GIT_SEQUENCE_EDITOR="sed -i -re 's/^pick ([0-9a-f]*) \.$/f \1 ./'" git rebase -i HEAD~${lineNumber}
echo "FYI, top 2 HEAD commits now ..."
git --no-pager log --oneline -n 2
else
echo "Need at least 1 . commit to squash with. Not squashing"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment