Amend a commit
Amending a commit in Git provides you with the ability to fine-tune and improve your commit history, ensuring a more accurate and organized record of your project's development. Whether you need to update commit messages, add or remove changes, or reorder commits, Git offers the flexibility to make these modifications to your existing commits.
In this part of our tutorial, we will explore the process of amending a commit in Git.
Go to the git-tutorial/tutorial1
directory you just downloaded.
When you examine the history of this repository, it will look like the following:
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 <yourname@yourmail.com>
Date: Mon Jul 16 23:17:56 2022 +0900
EDITED: append description of the add command
commit 0de54de5d846d5fb800cf0f4d74f0c79d2e0a186
Author: yourname <yourname@yourmail.com>
Date: Mon Jul 16 23:16:14 2022 +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:
$ 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