git - 更改 Git 历史记录中的电子邮件地址

标签 git git-filter-branch

我已经在 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/

相关文章:

git log - 查找指定字符串的添加

linux - 带有波形符 "~"(位于文件名末尾)的文件的全局 gitignore

Java 监控 GitHub 存储库

git - 将 git 存储库中的一组文件拆分到它们自己的存储库中,保留相关历史记录

git - filter-branch 仅在运行两次后才起作用

git - 如何替换 git 历史文件中的文本?

git 过滤器分支错误 : "fatal: Not a valid object name HEAD"

git merge : apply changes to code that moved to a different file

git - github 发行说明是否存储在 git 上?

Git:什么是 graftcommit 或 graft-id?