• Home
  • About
    • J Haigh photo

      J Haigh

      J Haigh is a software developer passionate about Haskell & Rust. They want to share the joy they've found in learning those languages with others. Strong and static types help make them more confident that their code will work in the future.

    • Learn More
    • Email
    • Twitter
    • Github
  • Posts
    • All Posts
    • All Tags

Remove Your Dead Name From Git Commits

18 Jan 2019

Reading time ~1 minute

For production environments or other places where you might need to preserve your git history, consider adding a .mailmap file to the top level of your directory instead. You can read more about how to use .mailmap files here. Thanks to Josh Triplett for suggesting this solution.

If you are looking for overwrite your git history on smaller, personal projects, you can

$ git filter-branch --commit-filter '
GIT_AUTHOR_NAME="[your name]"
GIT_COMMITTER_NAME="[your name]"
git commit-tree "$@"' -f
$ git push --force-with-lease

For a project that has multiple contributors you can something like the following:

git filter-branch --commit-filter '
if [ "$GIT_AUTHOR_NAME" = "[previous name]" ];
then
        GIT_AUTHOR_NAME="[new name]";
        GIT_COMMITTER_NAME="[new name]";
        git commit-tree "$@";
else
        git commit-tree "$@";
fi' HEAD

The previous example is slightly modified from one of the examples from the documentation on the filter-branch command.

Cheers to having only your chosen name in your git commits! 🎉

This blog post is a more searchable archive of this twitter thread.



git Share Tweet +1