Little Git Tricks: Change the Author of a Commit

Git tracks the author of every commit. If you do not modify anything, the global settings will be used. That is great for the day-to-day use, but it may not be what you want in all situations.

If you do pair-programming, you may want to make the commits as a team. If you commit your code on the command line, you can use this option with your commit:

If you have already committed your code (but not yet pushed it to the server), you can change the last commit it with this command:

Visual Studio, like most development environments, does not offer an easy way to change the author. In this case you can modify the default value in this specific repository. First check the current settings and then set them to the value you want to use:

If you now commit your code the correct name is recorded:

Don’t forget to change it back when your pair-programming session is over.

Should you ever need to change all commits by a specific author in a repository, you need something more powerful. First check if a mailmap is enough. If that works you just add this file and map the existing author to the new name.
Only when this is not sufficient should you use the script from GitHub to rewrite the whole history of your repository and replace the author info completely. Use this as the last resort, then now everyone needs a fresh checkout, or nothing will work.

 

Conclusion

Git offers many ways to change the author of a commit. With this selection you should be able to choose an option that works for you.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.