skip to content
Alvin Lucillo

Renaming the latest commit

/ 1 min read

Renaming the latest commit can be as easy as git commit --amend -m "new message". Note that this generates a new commit hash.

Here, the current commit message is add notes.

$ git show --stat
commit 1c38c9ac39f31e9a50d7c19349d1abd6cb47fb15
Author: <redacted>
Date: <redacted>

    add notes

 metadata | 1 +
 notes    | 1 +
 2 files changed, 2 insertions(+)

Notice that after the amend, it does not modify the commit in-place; it creates a new one and replaces the commit it amended.

$ git commit --amend -m "add notes and metadata"
[main 326a18c] add notes and metadata
 Date: <redacted>
 2 files changed, 2 insertions(+)
 create mode 100644 metadata
 create mode 100644 notes

$ git show --stat
commit 326a18ccaf5f20f2bebbb62ccbe11da2a99b9686
Author: <redacted>
Date: <redacted>

    add notes and metadata

 metadata | 1 +
 notes    | 1 +
 2 files changed, 2 insertions(+)