SoFunction
Updated on 2025-04-12

How to modify the username and email address of the author

git modify the username and email address of the author

Preface

The following two points need to be paid attention to:

  1. Need to be in the top directory (that is.gitIn the directory where the folder is located, right-click to open "Git Bash Here"), otherwise an error will be reported when running the following code;
  2. Make sure that the files in the repository to be modified are the same as the version of the remote repository. If there is any modification that has not been submitted yet, you need to submit or cancel the changes first, otherwise an error will be reported when running the following code.

first step

The following three main changes are:

  1. OLD_EMAIL:Fill in the email address before modification
  2. CORRECT_NAME:Fill in the current name
  3. CORRECT_EMAIL:Fill in your current email address

Then in "Git Bash Here” Run the code in the open window:

#!/bin/sh

git filter-branch --env-filter '

OLD_EMAIL="xxxx@"
CORRECT_NAME="chenmeng"
CORRECT_EMAIL="xxxx@"

if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_AUTHOR_NAME="$CORRECT_NAME"
export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags

Step 2

After executing the first step of the command, execute the following command and force push to the remote repository:

git push --force

Summarize

The above is personal experience. I hope you can give you a reference and I hope you can support me more.