Change Email Address in Git History

I worked on the git repository for some time and made some commits. I use documentation blocks in my php files, including my personal email address, for example:

/** * Bla bla bla. * * @author: Nic < foo@bar.com > */ 

Now I created a new email address and updated the documentation blocks, replacing the old address with the new one. But this change only applies to commit after where I changed the documentation.

How to completely remove the old email address from git history and replace all instances with the new address?

I tried using the git filter branch using this blog post but to no avail. I get the following result:

 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>...] 

Could it be that special characters of email addresses (@ and.) Confuse the regular expression? Other than that, I have no idea what is happening; any help is appreciated!

+7
source share
2 answers

I do not know why you are receiving a usage message. Copy and paste your command to run the filter for me. But in fact, he did not modify the files. This was really due to the @ characters in the email addresses that cause perl to treat @email as a list variable and replace it with (nonexistent) content. Therefore, the regular expression searched old-email.com .

This can be fixed by using \@ instead of the @ signs in the perl command. . in the old email address is a special character for regular expression, but it will match itself. In this case, the rest of the template is likely to be strict enough so that it doesn't matter, so you probably don't need to avoid it.

+4
source

Another option is to attempt to filter the branch this way:

 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 " $@ "' 
+3
source

All Articles