Kev*_*hen 10 git git-commit git-rewrite-history
所以我读了很多关于如何更改以前提交的电子邮件地址但由于某种原因我的更新没有.
我确实喜欢使用我的本地电子邮件(nameofMyComputer@kevin.local)对我的私人仓库进行了40次提交,这很糟糕,因为这封电子邮件与github没有关联(也不可能).
然后我记得我之前需要设置git.config,所以我做了:
git config user.email "newemail@example.com"
Run Code Online (Sandbox Code Playgroud)
并做了一个测试提交,它完美地工作.
有没有办法可以将我以前的所有提交还原到这封新邮件?
我在SO上阅读了这个问题.在Git中更改了作者和提交者名称以及多次提交的电子邮件并使用了它
git filter-branch -f --env-filter "
GIT_AUTHOR_EMAIL='kevin.cohen26@gmail.com';
GIT_COMMITTER_EMAIL='kevin.cohen26@gmail.com';
"
HEAD
Run Code Online (Sandbox Code Playgroud)
但它不起作用......我仍然可以看到我之前提交的电子邮件与.patch扩展名为.local电子邮件地址
Chr*_*aes 11
您确实可以像这样一次为许多提交执行此操作:
git rebase -i HEAD~40 -x "git commit --amend --author 'Author Name <author.name@mail.com>' --no-edit"
Run Code Online (Sandbox Code Playgroud)
正如您在问题中提到的(您找到的答案的链接),这确实是脚本.
filter-branch正在做一个rebase(将重写分支的历史记录),这意味着每个拥有分支副本的人都必须删除并再次签出.
脚本来源于此处 - Git-Tools-Rewriting-History:
# Loop over all the commits and use the --commit-filter
# to change only the email addresses
git filter-branch --commit-filter '
# check to see if the committer (email is the desired one)
if [ "$GIT_COMMITTER_EMAIL" = "<Old Email>" ];
then
# Set the new desired name
GIT_COMMITTER_NAME="<New Name>";
GIT_AUTHOR_NAME="<New Name>";
# Set the new desired email
GIT_COMMITTER_EMAIL="<New Email>";
GIT_AUTHOR_EMAIL="<New Email>";
# (re) commit with the updated information
git commit-tree "$@";
else
# No need to update so commit as is
git commit-tree "$@";
fi'
HEAD
Run Code Online (Sandbox Code Playgroud)
它循环遍历所有提交,一旦找到匹配,它就会替换提交者的名称和电子邮件.
| 归档时间: |
|
| 查看次数: |
7241 次 |
| 最近记录: |