1.修改历史提交记录的作者和用户名
执行脚本安装 git-filter-repo
brew install git-filter-repo
在开始操作之前,建议先备份仓库,备份方式
- git clone备份
git clone --bare https://github.com/your-username/your-repo.git your-repo-bare
- cp -r指令复制整个文件夹
cp -r your-repo your-repo-backup
备份且安装完成后cd到项目目录下,替换下方的errorName和newName,以及error@mail.com和new@mail.com,执行脚本后将会替换掉本地所有的历史提交记录
git filter-repo --force --replace-refs delete-no-add \
--commit-callback '
if commit.committer_name == b"errorName":
commit.committer_name = b"newName"
if commit.committer_email == b"error@mail.com":
commit.committer_email = b"new@mail.com"
if commit.author_name == b"errorName":
commit.author_name = b"newName"
if commit.author_email == b"error@mail.com":
commit.author_email = b"new@mail.com"
'
而后强制推送到远端
git push --force origin main
如果出现如下错误信息,表示没有设置远端仓库地址
Aborting: Refusing to destructively overwrite repo history since
this does not look like a fresh clone.
(expected freshly packed repo)
Please operate on a fresh clone instead. If you want to proceed
anyway, use --force.
使用git remote -v查看是否正确设置了仓库地址
git remote -v
如果没有看到 origin 远程仓库,或者 URL 错误,你需要设置或更新它。
git remote add origin https://github.com/your-username/your-repo.git
而后再次尝试推送到远端
git push --force origin main