LATEST 544d ago
Rewrites Git commit history across all branches and tags to replace old author/committer email addresses.
> CONFIGURE VARIABLES (CLICK HIGHLIGHTED CODE TO EDIT)
#!/usr/bin/env bash
# ==============================================================================
# Git Commit Author & Email History Rewriter
# Description: Rewrites Git commit history across all branches and tags to replace old author/committer email addresses.
# Usage: ./rewrite-git-history.sh "old.email@example.com" "new_username" "new.email@example.com"
# ==============================================================================
set -euo pipefail
export FILTER_BRANCH_SQUELCH_WARNING=1
WRONG_EMAIL="${1:-${OLD_EMAIL:-old.email@example.com}}"
NEW_NAME="${2:-${NEW_NAME:-new_username}}"
NEW_EMAIL="${3:-${NEW_EMAIL:-new.email@example.com}}"
echo "[INFO] Rewriting Git Commit History"
echo "----------------------------------------------------"
echo "Target Old Email : ${WRONG_EMAIL}"
echo "New Author Name : ${NEW_NAME}"
echo "New Author Email : ${NEW_EMAIL}"
echo "----------------------------------------------------"
git filter-branch -f --env-filter '
TARGET_WRONG_EMAIL="'"${WRONG_EMAIL}"'"
TARGET_NEW_NAME="'"${NEW_NAME}"'"
TARGET_NEW_EMAIL="'"${NEW_EMAIL}"'"
if [ "$GIT_COMMITTER_EMAIL" = "$TARGET_WRONG_EMAIL" ]; then
export GIT_COMMITTER_NAME="$TARGET_NEW_NAME"
export GIT_COMMITTER_EMAIL="$TARGET_NEW_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$TARGET_WRONG_EMAIL" ]; then
export GIT_AUTHOR_NAME="$TARGET_NEW_NAME"
export GIT_AUTHOR_EMAIL="$TARGET_NEW_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags
echo ""
echo "[OK] Git history rewrite completed successfully!"
echo "[NOTE] To force push changes to remote: git push origin --force --all && git push origin --force --tags"
1 #!/usr/bin/env bash
2 # ==============================================================================
3 # Git Commit Author & Email History Rewriter
4 # Description: Rewrites Git commit history across all branches and tags to replace old author/committer email addresses.
5 # Usage: ./rewrite-git-history.sh "old.email@example.com" "new_username" "new.email@example.com"
6 # ==============================================================================
7 set -euo pipefail
8
9 export FILTER_BRANCH_SQUELCH_WARNING=1
10
11 WRONG_EMAIL="${1:-${OLD_EMAIL:-old.email@example.com}}"
12 NEW_NAME="${2:-${NEW_NAME:-new_username}}"
13 NEW_EMAIL="${3:-${NEW_EMAIL:-new.email@example.com}}"
14
15 echo "[INFO] Rewriting Git Commit History"
16 echo "----------------------------------------------------"
17 echo "Target Old Email : ${WRONG_EMAIL}"
18 echo "New Author Name : ${NEW_NAME}"
19 echo "New Author Email : ${NEW_EMAIL}"
20 echo "----------------------------------------------------"
21
22 git filter-branch -f --env-filter '
23 TARGET_WRONG_EMAIL="'"${WRONG_EMAIL}"'"
24 TARGET_NEW_NAME="'"${NEW_NAME}"'"
25 TARGET_NEW_EMAIL="'"${NEW_EMAIL}"'"
26
27 if [ "$GIT_COMMITTER_EMAIL" = "$TARGET_WRONG_EMAIL" ]; then
28 export GIT_COMMITTER_NAME="$TARGET_NEW_NAME"
29 export GIT_COMMITTER_EMAIL="$TARGET_NEW_EMAIL"
30 fi
31 if [ "$GIT_AUTHOR_EMAIL" = "$TARGET_WRONG_EMAIL" ]; then
32 export GIT_AUTHOR_NAME="$TARGET_NEW_NAME"
33 export GIT_AUTHOR_EMAIL="$TARGET_NEW_EMAIL"
34 fi
35 ' --tag-name-filter cat -- --branches --tags
36
37 echo ""
38 echo "[OK] Git history rewrite completed successfully!"
39 echo "[NOTE] To force push changes to remote: git push origin --force --all && git push origin --force --tags"
40