背景
使用一台二手电脑做开发工作,提交了几次代码后发现,commit的名称是旧主,需要修改之前提交的的commit作者
步骤
<1> 在windows下删除掉非自己的有关github的普通凭证

<2> 修改之后提交commit的作者的方式是: 进入到自己的git repo下面修改邮箱和用户名,这样以后的提交的变成自己的,但是试验了多次没成功,于是跳到第三步执行
git config --global user.email "youremail@googl.com"
git config --global user.name "your name"
<3> 根据官方的github推荐的操作执行 https://docs.github.com/en/github/using-git/changing-author-info
/1/ 重新拉取git repo,注意一定要重新拉取,不要本地的git repo里面执行如下操作,防止破坏了git仓库历史
git clone --bare https://github.com/user/repo.git
cd repo.git
/2/ 进入到repo.git 创建新的脚本,OLD_EMAIL改成之前的commit作者邮箱,CORRECT_NAME和CORRECT_EMAIL改成自己的名称和邮箱,然后执行该脚本
#!/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
过程中会出现如下信息

/3/ 推仓库到远程,删除新拉的repo
git push --force --tags origin 'refs/heads/*'
cd ..
rm -rf repo.git
/4/ 由于<2>中的操作没起到作用,重新从远端拉取了仓库,然后在这个新拉取的仓库下开发,如果<2>中修改name和email的方式起到作用,此步可以忽略