Created
June 17, 2021 11:54
-
-
Save kristijorgji/24ff1076a9bbe727535578bf04d15286 to your computer and use it in GitHub Desktop.
git-rewrite.sh
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/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