threads / discuss / 27429

Using git-replace to edit a commit message?

Subject: Using git-replace to edit a commit message?

## tl;dr

2 messages between May 22, 2011 and May 23, 2011.

replies: 1people: 2as markdown or json

Joe Smith· May 22, 2011, 22:11 UTC · lore

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?

Junio C Hamano· May 23, 2011, 02:11 UTC · re: Joe Smith · lore

Re: Using git-replace to edit a commit message?

Joe Smith <unknown_kev_cat@hotmail.com> writes:
> Is there some reason that will not work? If it would work, is there
> some reason nobody ever seems to suggest it?

It would; I think the real reason is because it is not worth the trouble for asking everybody to trust your replace refs and install them in their repository and pay the runtime cost. Most people just move on once their mistakes are public.

← back to recent threads