如何修改Github上提交的错误用户地址和姓名
Changing author info
To change the name and/or email address recorded in existing commits, you must rewrite the entire history of your Git repository.
Warning: This action is destructive to your repository's history. If you're collaborating on a repository with others, it's considered bad practice to rewrite published history. You should only do this in an emergency.
Changing the Git history of your repository using a script
We've created a script that will change any commits that previously had the old email address in its author or committer fields to use the correct name and email address.
Note: Running this script rewrites history for all repository collaborators. After completing these steps, any person with forks or clones must fetch the rewritten history and rebase any local changes into the rewritten history.
Before running this script, you'll need:
- The old email address that appears in the author/committer fields that you want to change
-
The correct name and email address that you would like such commits to be attributed to
-
Open Terminal (for Mac users) or the command prompt (for Windows and Linux users).
-
Create a fresh, bare clone of your repository:
git clone --bare https://github.com/user/repo.git cd repo.git
-
Copy and paste the script, replacing the following variables based on the information you gathered:
OLD_EMAIL
CORRECT_NAME
CORRECT_EMAIL
12345678910111213141516171819#!/bin/sh
git filter-branch --
env
-filter '
OLD_EMAIL=
"your-old-email@example.com"
CORRECT_NAME=
"Your Correct Name"
CORRECT_EMAIL=
"your-correct-email@example.com"
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
- Press Enter to run the script.
- Review the new Git history for errors.
-
Push the corrected history to GitHub:
git push --force --tags origin 'refs/heads/*'
-
Clean up the temporary clone:
cd .. rm -rf repo.git
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?