Skip to main content
  1. Learn
  2. Software Development
  3. Guides
  4. Git tutorial
  5. How to use Git
  6. How to manage history in Git
  7. Modify a commit
GuidesSoftware DevelopmentBacklog

Project and code management together.

Modify a commit

Go to the git-tutorial/tutorial1 directory you just downloaded.

When you examine the history of this repository, it will look like the following:

The history of repository

To confirm the repository’s history, use the git log command and you will see the following:

$ git log
commit f01c8c09f09e14063feb13b24be592e507ea365b (HEAD -> main)
Author: yourname <>
Date:   Mon Jul 16 23:17:56 2012 +0900
    EDITED: append description of the add command
commit 0de54de5d846d5fb800cf0f4d74f0c79d2e0a186
Author: yourname <>
Date:   Mon Jul 16 23:16:14 2012 +0900
    first commit

Let’s rewrite the first commit in the history log.

First, open the sample.txt file and add the bold text below.

Anyone can learn Git with this tutorial and Backlog add: Register a change in an index commit: Save the status of an index

Commit with the --amend option.

$ git add sample.txt
$ git commit --amend

Your default editor will open containing the latest commit message, which you can edit. For this tutorial, let’s change the message to “Add direction of the Add and the Commit,” then save and exit the text editor.

The commit message is now updated. Use the log command again to verify that the repository history and the new commit message look like this:

the result of "commit --amend"
$ git log
commit e9d75a02e62814541ee0410d9c1d1bf47ab1c057
Author: yourname
Date:   Mon Jul 16 23:17:56 2022 +0900

    Add direction of the Add and the Commit

commit 48eec1ddf73a7fb508ef664efd6b3d873631742f
Author: yourname
  Date:   Mon Jul 16 23:16:14 2022 +0900

      first commit

Subscribe to our newsletter

Learn with Nulab to bring your best ideas to life