我已经在 git 存储库上工作了一段时间并进行了一些提交。我一直在我的 php 文件中使用文档 block ,包括我的私有(private)电子邮件地址,如下所示:
/**
* Bla bla bla.
*
* @author: Nic <foo@bar.com>
*/
现在我已经创建了一个新的电子邮件地址并更新了文档 block ,将旧地址替换为新地址。但此更改仅适用于我更改文档后的提交。
我怎样才能从 git 的历史记录中完全删除旧的电子邮件地址并用新地址替换所有实例?
我尝试使用 this blog post 使用 git filter-branch但没有成功。我得到以下结果:
git filter-branch --tree-filter 'git ls-files -z "*.php" |xargs -0 perl -p -i -e "s#old-email@example.com#new-email@foobar.com#g"' -- --all
Usage: git core\git-filter-branch [--env-filter <command>] [--tree-filter <command>]
[--index-filter <command>] [--parent-filter <command>]
[--msg-filter <command>] [--commit-filter <command>]
[--tag-name-filter <command>] [--subdirectory-filter <directory>]
[--original <namespace>] [-d <directory>] [-f | --force]
[<rev-list options>...]
会不会是电子邮件地址的特殊字符(@ 和 .)弄乱了正则表达式?除此之外,我不知道出了什么问题,感谢任何帮助!
最佳答案
另一种选择是以这种方式尝试过滤器分支:
git filter-branch --commit-filter 'if [ "$GIT_AUTHOR_NAME" = "Nick NLD" ];
then export GIT_AUTHOR_EMAIL=your_new_email@example.com;
fi; git commit-tree "$@"'
关于git - 更改 Git 历史记录中的电子邮件地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13552143/