git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Using git-replace to edit a commit message?

From
JSJoe Smith <unknown_kev_cat@hotmail.com>
Date
May 22, 2011, 22:11 UTC
Message-ID
<loom.20110523T001117-737@post.gmane.org>

A somewhat common question with Git is how to change a commit message of an already created commit.

When this question comes up, the most common case is an unpublished commit, which can safely be corrected by re-writing history.

Occasionally the question is about a published commit. Sometimes even for published repositories rewriting history is acceptable, but often it is not. In that case the usual answer is either: there is nothing you can do without rewriting history, or add a note to the commit.

Is that really true?

It occurs to me that the following procedure should work rather well for this, as long as it is not a frequent occurrence.

Create a new commit object with the correct text (or correct author, or correct committer), ensuring that the the listed tree and parent SHA-1 hashes are correct (i.e. are the same those hashes in the commit being "edited").

Then simply use git-replace to have all references to the "unedited" commit instead use this new commit.

Is there some reason that will not work? If it would work, is there some reason nobody ever seems to suggest it?

Next: Junio C Hamano
Message 1 of 2 in “Using git-replace to edit a commit message?”
  1. Joe SmithMay 22, 2011
  2. Junio C HamanoMay 23, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.