Created
July 5, 2014 18:08
-
-
Save esebastian/f0678f8a1dd34e361fd7 to your computer and use it in GitHub Desktop.
Apply messages from provided input file to git commits with empty messages
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/sh | |
# Apply messages from provided input file to commits with empty messages | |
# The messages are applied in inverse order (first line in the file applied to older commit with void message) | |
# and only up to the number of commits with empty messages. | |
# | |
# This action is destructive to your repo's history. It's best to do this on a clone, | |
# just in case. Also beware that this should not be performed on a repo that has been | |
# shared with others without forcing them to reset their history. | |
# | |
# Use at your own risk. | |
# | |
# Put the script in your path and invoke it this way: | |
# git unvoid-messages <inputfile> | |
if [[ ! -n $1 ]]; then | |
echo "usage: git unvoid-messages <inputfile>\n" | |
exit 1 | |
fi | |
echo "Unvoiding messages with contens from $1..." | |
cp $1 $1.tmp | |
export input_file=$PWD/$1.tmp | |
git filter-branch -f --msg-filter ' | |
read msg | |
if [ -z "$msg" ]; then | |
msg=`head -n 1 $input_file` | |
sed -i "" -e "1d" $input_file | |
fi | |
echo "$msg" | |
' | |
rm $1.tmp | |
unset input_file | |
[[ $? -eq 0 ]] && echo Done! | |
[[ $? -ne 0 ]] && echo Error! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment