Nic*_*tel 7 git git-filter-branch
我已经在git仓库工作了一段时间并做了一些提交.我一直在我的php文件中使用文档块,包括我的私人电子邮件地址,如下所示:
/**
* Bla bla bla.
*
* @author: Nic <foo@bar.com>
*/
Run Code Online (Sandbox Code Playgroud)
现在我创建了一个新的电子邮件地址并更新了文档块,用新的地址替换了旧地址.但是这个更改仅适用于我更改文档之后的提交.
如何从git的历史记录中完全删除旧的电子邮件地址并用新地址替换所有实例?
我尝试过使用这个博客文章使用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>...]
Run Code Online (Sandbox Code Playgroud)
可能是电子邮件地址(@和.)的特殊字符搞乱了正则表达式吗?除此之外我不知道出了什么问题,任何帮助表示赞赏!
看到Git开始显示
\nWARNING: git-filter-branch has a glut of gotchas [\xe2\x80\xa6] use an\n alternative filtering tool such as \'git filter-repo\'\n (https://github.com/newren/git-filter-repo/) instead.\nRun Code Online (Sandbox Code Playgroud)\n等效的命令是:
\ngit-filter-repo --email-callback \\\n \'return email.replace(b"old@dusty.tld", b"new@shiny.tld")\'\nRun Code Online (Sandbox Code Playgroud)\n
另一种选择是以这种方式尝试filter-branch:
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 "$@"'
Run Code Online (Sandbox Code Playgroud)