[Git] Modify last commit author

[Git] Modify last commit author

2023-04-08 hit count image

Let's see how to modify the author of the last commit with Git amend and author options.

Outline

When you use multiple Git accounts, you may commit as the wrong user. Fot this, Git provides the amend option to modify the commit message and the author option to modifyt the author of the commit message.

In this blog post, I will introduce how to modify the last commit message author with the amend and author options of Git.

If you want to know how to modify the last commit message with the amend option of Git, please see the following link.

git log

First, let’s check the current Git status by executing the git log command like the following.

git log

And then, you can see the last commit message in it.

commit f645e50a1daeaafe08d19aae71d9ad6a7f33dce1 (HEAD -> main)
Author: dev-yakuza <[email protected]>
Date:   Thu Apr 6 14:20:06 2023 +0900

    Add test.txt file

Check and modify the current user

You can check the current configured user’s name and email by executing the following command.

git config user.name
git config user.email

When you execute them, you can see the user information like the following.

# git config user.name
dev-yakuza
# git config user.email
[email protected]

And then, execute the following command to modify the correct user.

git config --global user.name USER_NAME
git config --global user.email USER_EMAIL

This command uses the --global option, so this user becomes default author when you commit the other repositories. If you want to change the author for only current repository, execute the command without the --global option like the following.

git config user.name USER_NAME
git config user.email USER_EMAIL

To check the user changed well, execute the following command.

git config user.name
git config user.email

And then, you can see the user chaged well.

# git config user.name
USER_NAME
# git config user.email
USER_EMAIL

This process is not required for changing the last commit author, but You can still write messages as the wrong user, so we introduced them here.

git commit –amend –author

Now, let’s see how to modify the author of the last commit. Execute the git commit --amend --author command like the following to modify the last commit author.

git commit --amend --author="USER_NAME<USER_EMAIL>"

After executing the command, you can see the vi editor to modify the commit message.

Add test.txt file

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date:      Tue Oct 25 14:47:16 2022 +0900
#
# On branch main
# Changes to be committed:
#       modified:   test.txt

We just want to change the author not message, so press :q to quit the editor. And then, execute the git log to check the author is chanaged well.

git log

If there is no problem to modify the author, you can see the author changed well like the following.

commit 2b75330783b0385855f750962a400807eb38a993 (HEAD -> main)
Author: USER_NAME <USER_EMAIL>
Date:   Thu Apr 6 14:20:06 2023 +0900

    Add test.txt file

Completed

Done, we’ve seen how to modify the author of the last commit by executing the amend and author option of Git. When you use the company account and personal account, or when you use multiple accounts, sometimes you commit as the wrong user. At this time, try to use the amend and author option to modify the correct user.

If you commit with the wrong commit message, please see the following link to modify the last commit message.

Was my blog helpful? Please leave a comment at the bottom. it will be a great help to me!

App promotion

You can use the applications that are created by this blog writer Deku.
Deku created the applications with Flutter.

If you have interested, please try to download them for free.

Posts