How to reword a Git commit by its SHA1 hash?

I have created a commit with a commit message that I want to modify. I have not published the commit, yet, so I can rewrite history safely. I can find using git log, so I know its sha1 hash. How can I quickly edit the commit?


You can checkout the commit in question, amend its message and rebase back to your branch manually:

$ git checkout FIRST_COMMIT_SHA
$ git commit --amend

This git alias will automate this process:

reword = "!f() { branch=`git symbolic-ref --short HEAD`; git checkout $1; git commit --amend; git checkout $branch; }; f"

To add it to your ~/.gitconfig:

$ git config alias.reword "!f() { branch=`git symbolic-ref --short HEAD`; git checkout $1; git commit --amend; git checkout $branch; }; f"

Then use like this:



Alternatively, amending the initial commit message can be accomplished by using the rebase command and supplying the --root flag. In addition, you would need to specify interactive mode and use edit for the first commit, like so:

git rebase -i -root

// Specify 'edit' for the first commit.

// Amend first commit message here.
git commit --amend

See here for further details on the --root flag.

Also, provided that the commit with the message you want to modify is in the branch you are working on, you could easily solve that with interactive rebase too. Simply locate the corresponding short SHA-1 and specify edit to allow modification of its commit message.

Need Your Help

Android SampleBrowserPlugin Installation failed

android android-ndk npapi android-source

I am trying to install the samplebrowserplugin given in the android source code. As given here (, I am able to foll...

How do I send a list to the jsp that requested it?

java java-ee servlets jsp-tags

Let us suppose there is a jsp that needs to display the list of files shared shared by a particular IP. Client opens that jsp on his local server and the request is sent to a remote server to fetch...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.