Last active
July 9, 2025 09:14
-
-
Save wazum/960e7827d9ceefbb18df8601d370b480 to your computer and use it in GitHub Desktop.
Simple bash script to prefix (with replace) a bunch of git commit messages in bulk
This file contains hidden or 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 | |
PREFIX="[SOMETHING]" | |
# Add commit hashes from newest to oldest (oldest at the end). | |
COMMITS=( | |
90f94f6174d9efe74d5f63a53049a063124bdff8 | |
eb17a70cf18ea6662c045b95ac5ba6a36640b30c | |
91026eec2b324e6999b07fc24071fa0e55dd2795 | |
411df442fbe4860f6b25fc41d8a4fc64190a95fa | |
1f5cf10b34fc67677f00fe7850730bdfe38c1ff9 | |
) | |
OLDEST=${COMMITS[${#COMMITS[@]}-1]} | |
cat > /tmp/reword-commits.sh << 'EOF' | |
#!/bin/bash | |
FILE="$1" | |
EOF | |
for commit in "${COMMITS[@]}"; do | |
SHORT=$(git rev-parse --short $commit) | |
echo "sed -i.bak 's/^pick $SHORT/reword $SHORT/' \"\$FILE\"" >> /tmp/reword-commits.sh | |
done | |
echo "rm -f \"\$FILE.bak\"" >> /tmp/reword-commits.sh | |
chmod +x /tmp/reword-commits.sh | |
cat > /tmp/add-prefix.sh << EOF | |
#!/bin/bash | |
sed -i.bak '1s/^\[[^]]*\] /$PREFIX /' "\$1" | |
sed -i.bak2 '1s/^[^[]/$PREFIX &/' "\$1" | |
rm -f "\$1.bak" "\$1.bak2" | |
EOF | |
chmod +x /tmp/add-prefix.sh | |
export GIT_SEQUENCE_EDITOR="/tmp/reword-commits.sh" | |
export EDITOR="/tmp/add-prefix.sh" | |
git rebase -i $OLDEST^ | |
rm -f /tmp/reword-commits.sh /tmp/add-prefix.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment