Created
May 31, 2016 16:31
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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