Created
July 18, 2025 12:06
-
-
Save Liam0205/e55d89494d3b61a5bea96ee3d1ef15ab to your computer and use it in GitHub Desktop.
Git Author Email and Name Batch Modification Script
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/bash | |
# =============================================================================== | |
# Git Author Email and Name Batch Modification Script | |
# =============================================================================== | |
# | |
# DESCRIPTION: | |
# This script allows you to retroactively modify the author email and name | |
# for a range of Git commits. It uses interactive rebase to systematically | |
# update commit author information while preserving original commit dates | |
# and other metadata. | |
# | |
# USE CASES: | |
# - Correcting author information after accidental commits with wrong email | |
# - Updating author details for privacy or organizational requirements | |
# - Standardizing author information across a project's history | |
# - Fixing commits made with incorrect Git configuration | |
# | |
# PREREQUISITES: | |
# - Git repository with commit history | |
# - No uncommitted changes in the working directory | |
# - Backup of your repository recommended before running | |
# | |
# USAGE: | |
# 1. Edit the configuration variables below (NEW_EMAIL, NEW_NAME, START_COMMIT) | |
# 2. Ensure your working directory is clean | |
# 3. Run the script: bash modify_email.sh | |
# 4. In the interactive rebase editor, mark commits as 'edit' and save | |
# 5. The script will automatically process each commit | |
# | |
# WARNING: | |
# This script modifies Git history and should be used with caution. | |
# Force pushing may be required if the branch has been shared. | |
# Always backup your repository before running this script. | |
# | |
# =============================================================================== | |
# Configuration Variables | |
NEW_EMAIL="[email protected]" | |
NEW_NAME="Foo Bar" | |
# Starting commit hash (from which commit to start modifying) | |
START_COMMIT="c4a77a5" | |
# Get all commits from the specified commit to HEAD | |
commits=$(git rev-list --reverse $START_COMMIT..HEAD) | |
echo $commits | |
# Start interactive rebase | |
# In the editor, mark each commit as 'edit', then save and exit | |
git rebase -i $START_COMMIT | |
# Iterate through each commit for modification | |
for commit in $commits; do | |
# Get the original author and time information of the commit | |
AUTHOR=$(git show -s --format='%an <%ae>' $commit) | |
DATE=$(git show -s --format='%ad' --date=iso $commit) | |
# Execute modification operation on each commit | |
GIT_COMMITTER_DATE="$DATE" git commit --amend --no-edit --author="$AUTHOR" --date="$DATE" --author="$NEW_NAME <$NEW_EMAIL>" | |
# Manually execute git rebase --continue | |
git rebase --continue | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment