Skip to content

Instantly share code, notes, and snippets.

@tw3
Last active January 27, 2022 17:15
Show Gist options
  • Save tw3/494eca55f8d8968dd242a3bdbbe1c2fd to your computer and use it in GitHub Desktop.
Save tw3/494eca55f8d8968dd242a3bdbbe1c2fd to your computer and use it in GitHub Desktop.
Git Bash "script" (for Windows OS) to modify commit messages in bulk, e.g. if you made a bunch of commits listing one ticket id, then decided to create a sub-task ticket and need to update your commits to use that id instead
#!/usr/bin/env bash
main() {
echo "Here's an example:"
echo ""
echo "\"C:/Program Files/Python39/python.exe\" c:/bin/git-filter-repo.py --commit-callback '"
echo "msg = commit.message.decode(\"utf-8\")"
echo "newmsg = msg.replace(\"TEXT_FROM\", \"TEXT_TO\")"
echo "commit.message = newmsg.encode(\"utf-8\")"
echo "' --force --refs pilot..BRANCH_NAME"
echo ""
echo "1) Copy that into an editor"
echo "2) Change TEXT_FROM and TEXT_TO and BRANCH_NAME"
echo "3) Run it in your shell :)"
echo ""
echo "For more details visit: https://stackoverflow.com/a/62458610"
}
main "${@}"
@tw3
Copy link
Author

tw3 commented Jan 27, 2022

You can find download git-filter-repo.py here:

https://github.com/newren/git-filter-repo/blob/main/git-filter-repo

Of course you may need to update the path to python on your machine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment