Skip to content

Instantly share code, notes, and snippets.

@smootoo
smootoo / gsquash
Created May 31, 2016 16:31
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 ..."