Change the Last Commit's Author

GitGitBeginner
Practice Now

This tutorial is from open-source community. Access the source code

Introduction

Git is a powerful version control system that allows developers to track changes made to their codebase. One of the features of Git is the ability to modify the last commit's author without changing its contents. This can be useful in situations where the author of a commit needs to be updated for accuracy or accountability purposes.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL git(("`Git`")) -.-> git/BasicOperationsGroup(["`Basic Operations`"]) git/BasicOperationsGroup -.-> git/commit("`Create Commit`") subgraph Lab Skills git/commit -.-> lab-12708{{"`Change the Last Commit's Author`"}} end

Change the Last Commit's Author

You have just made a commit to your Git repository, but you realized that the author's name and email address are incorrect. You want to update the author's information without changing the contents of the commit. How can you achieve this using Git?

To change the last commit's author, you can use the git commit --amend command. This command allows you to modify the last commit in your Git repository. Here's an example of how you can change the author's name and email address:

  1. Clone the Git repository named https://github.com/labex-labs/git-playground to your local machine:
git clone https://github.com/labex-labs/git-playground.git
  1. Configure Git's identity information using your GitHub account:
cd git-playground
git config user.email "your email"
git config user.name "your username"
  1. Use the git commit --amend command to modify the last commit's author and save the contents:
git commit --amend --author="Duck Quackers <cool.duck@qua.ck>"
  1. Verify that the author's information has been updated:
git log

You should see that the last commit's author is now Duck Quackers:

commit d5a385cc354f3528472a215b66cbb7c628ba47d5
Author: Duck Quackers <cool.duck@qua.ck>
Date:   Wed Apr 26 14:16:25 2023 +0800

    Added file2.txt

Summary

In this lab, you learned how to change the last commit's author without changing its contents using the git commit --amend command. This can be useful in situations where the author's information needs to be updated for accuracy or accountability purposes.

Other Git Tutorials you may like