DEV Community

Maaz Ahmed Khan
Maaz Ahmed Khan

Posted on

💬 Changing Git Config for Previous Commits

There may be occasions where you want to change the author name or email address for a commit you made earlier. This could be because you mistakenly used the wrong email address, or perhaps you want to conceal your identity for some reason. Whatever the case may be, you can easily change the author name and email address for previous commits by using the "filter-branch" command.
The "filter-branch" command rewrites the Git history by applying a filter to each commit. To change the author name and email address for previous commits, you can use the following command:

git filter-branch --commit-filter '
if [ "$GIT_AUTHOR_EMAIL" = "oldEmail.com" ];
then
GIT_AUTHOR_NAME="newAutherName";
GIT_AUTHOR_EMAIL="newaAutherEmail.com";
git commit-tree "$@";
else
git commit-tree "$@";
fi' HEAD

Top comments (0)