Skip to content

Instantly share code, notes, and snippets.

@kristijorgji
Created June 17, 2021 11:54
Show Gist options
  • Save kristijorgji/24ff1076a9bbe727535578bf04d15286 to your computer and use it in GitHub Desktop.
Save kristijorgji/24ff1076a9bbe727535578bf04d15286 to your computer and use it in GitHub Desktop.
git-rewrite.sh
#!/bin/sh
#===============================================================================
# This script will rewrite the history of your git commits based on the if condition below at line 20
# In this personal usage example, I add email to all commits that are without email set, and set my correct name
#===============================================================================
export GIT_REWRITE_LOG_FILE=/git-rewrite.log
echo '' > $GIT_REWRITE_LOG_FILE;
#git filter-branch -f --env-filter '
git filter-branch --env-filter '
NEW_NAME="Kristi Jorgji"
NEW_EMAIL="[email protected]"
function log() {
ts=$(date +'%F_%H_%M_%S');
echo "[$ts] $1" >> ${GIT_REWRITE_LOG_FILE};
}
if [ "$GIT_AUTHOR_EMAIL" = "=" ]
then
log "$GIT_COMMIT";
log "*** Renaming commiter name, email and author name email for this commit ***";
log "$GIT_COMMITTER_NAME => $NEW_NAME";
log "$GIT_COMMITTER_EMAIL => $NEW_EMAIL";
log "$GIT_AUTHOR_NAME => $NEW_NAME";
log "$GIT_AUTHOR_EMAIL => $NEW_EMAIL";
log "------------------------------------------------------\n"
export GIT_COMMITTER_NAME="$NEW_NAME"
export GIT_COMMITTER_EMAIL="$NEW_EMAIL"
export GIT_AUTHOR_NAME="$NEW_NAME"
export GIT_AUTHOR_EMAIL="$NEW_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment