Could I change my name and surname in all previous commits? Could I change my name and surname in all previous commits? git git

Could I change my name and surname in all previous commits?


Use git-filter-branch.

git filter-branch --commit-filter 'if [ "$GIT_AUTHOR_NAME" = "Josh Lee" ];  then export GIT_AUTHOR_NAME="Hobo Bob"; export GIT_AUTHOR_EMAIL=hobo@example.com;  fi; git commit-tree "$@"'

This only affects the author, not the committer (which for most commits will be the same as the author). If you want to rewrite those as well, set the GIT_COMMITTER_NAME and GIT_COMMITTER_EMAIL variables.

The standard warning about rewriting history applies; only do it to history that has not yet been shared.

June 2018 Update

The manual now includes a solution, using --env-filter, in its examples: https://git-scm.com/docs/git-filter-branch#_examples :

git filter-branch --env-filter '    if test "$GIT_AUTHOR_EMAIL" = "root@localhost"    then        GIT_AUTHOR_EMAIL=john@example.com    fi    if test "$GIT_COMMITTER_EMAIL" = "root@localhost"    then        GIT_COMMITTER_EMAIL=john@example.com    fi' -- --all


To rewrite both author and commiter in all selected commits:

git filter-branch --commit-filter \'if [ "$GIT_AUTHOR_NAME" = "OldAuthor Name" ]; then \export GIT_AUTHOR_NAME="Author Name";\export GIT_AUTHOR_EMAIL=authorEmail@example.com;\export GIT_COMMITTER_NAME="Commmiter Name";\export GIT_COMMITTER_EMAIL=commiterEmail@example.com;\fi;\git commit-tree "$@"'


If there are no other authors, you can do:

git filter-branch --commit-filter 'export GIT_AUTHOR_NAME="authorname"; \export GIT_AUTHOR_EMAIL=mail@example.com; git commit-tree "$@"'