# Using git-replace to edit a commit message?

2 messages from 2011-05-22 to 2011-05-23. Participants: Joe Smith, Junio C Hamano.
Thread: https://gitlist.dev/t/27429

## Joe Smith, 2011-05-22 22:11

Subject: Using git-replace to edit a commit message?
Message-ID: <loom.20110523T001117-737@post.gmane.org>
URL: https://gitlist.dev/e/loom.20110523T001117-737%40post.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?

```

## Junio C Hamano, 2011-05-23 02:11

Subject: Re: Using git-replace to edit a commit message?
Message-ID: <7vpqnaw4gy.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vpqnaw4gy.fsf%40alter.siamese.dyndns.org
In-Reply-To: <loom.20110523T001117-737@post.gmane.org>

```
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.

```
