Skip to content

Instantly share code, notes, and snippets.

@alvmgdev
Last active February 5, 2020 20:29
Show Gist options
  • Save alvmgdev/239c29addf318b2e7a389f9e06523879 to your computer and use it in GitHub Desktop.
Save alvmgdev/239c29addf318b2e7a389f9e06523879 to your computer and use it in GitHub Desktop.
git rebase -i <initial_commit_hash_to_rebase> -x <full_path_to_bulkCommitRename.sh>
#!/bin/bash
# Author: Alvaro Merino Garcia
# The purpose of this script is to use it as param of rebase -x "this script using full path"
# to process a bulk rename of commits
STRING_TO_BE_REPLACED="STRY0000000"
DESIRED_STRING_USING_IN_REPLACE="STRY1111111"
# Retrieve actual commit message using git log -1
COMMIT_MSG="$(git log --pretty=format:%s -1)"
# Transform the commit msg using sed
DESIRED_COMMIT_MSG="$(sed s/${STRING_TO_BE_REPLACED}/${DESIRED_STRING_USING_IN_REPLACE}/g <<< ${COMMIT_MSG})"
# Commit amend with desired commit msg
git commit --amend --no-edit -m "${DESIRED_COMMIT_MSG}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment