Follow us on X (Twitter)  Like us on Facebook  Connect with us on LinkedIn  Subscribe to our YouTube Channel  Subscribe to our WhatsApp Group

There could be various reasons when you would like to amend your last commit. One of them is improper commit message and/or wrong committer information. In any of the case, you may like to change the previous commit.

 

In this small post, we will learn how to amend your last Git commit message as well as the committer information (username and email). Continue reading to know more.

 

How to amend your last commit in Git repository? (www.kunal-chowdhury.com)

 

Git allows you to rewrite its commit history using the command 'git commit --amend', but it actually does not modify the previous commit, instead it rewrites the entire commit snapshot to repository. Before amending your previous commit, make sure that, no other user has pulled your last committed changes.

 

In case, your original Git commit was pulled by someone and then if you rewrite the commit history, it will actually override the previous commit and thus the pulled author will not find the actual reference of the changed content. Hence, it is advisable not to amend a commit if you already pushed it to public repository. Please find below various cases and commands to perform this operation.

 

Amend a commit giving user a choice to update the commit message:

$ git commit --amend

 

Amend a commit replacing the previous commit message:

$ git commit --amend -m "New commit message"

 

Amend a commit with author details:

$ git commit --amend --author="Author Name <Author Email Address>"

 

 

I hope, you liked the post. If you came to this page by searching online about git basics or git tutorials, please have a look into my other blog posts. Subscribe to the RSS feed or the email newsletter to keep yourself updated. If you have any queries, you can either ping me on Twitter or drop a line below in the comments section. Have a great day!

 

 

 

Have a question? Or, a comment? Let's Discuss it below...

Thank you for visiting our website!

We value your engagement and would love to hear your thoughts. Don't forget to leave a comment below to share your feedback, opinions, or questions.

We believe in fostering an interactive and inclusive community, and your comments play a crucial role in creating that environment.