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

Re: Edit log message after commit

From
Junio C Hamano <junkio@cox.net>
Date
Sep 29, 2005, 04:15 UTC
Message-ID
<7vr7b8pl0n.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<dhfjcu$36f$1@sea.gmane.org>
Kevin Leung <hysoka@gmail.com> writes:
> Is there any method to edit the log message after committed? I
> couldn't find any information in Documentation and in git
> mailing list.

Undoing and re-committing can be done with the following recipe.

There is a *big* *red* *warning*, though. If you have already made available the commit you are about to undo to others, and later other people have made more commits on top of them, merging their changes back to your repository would make the commit history look a bit funny. You could still do this without damaging the repository. This warning only applies to the shape of the commit graph.

First, the easiest case. Undoing and recommitting the latest commit in the current branch.

(1) Run "git diff HEAD" and make sure that your working tree
    matches the latest commit you are about to undo.  Then:
    $ git reset --soft HEAD^
    This leaves the working tree intact (i.e. it still has what
    you to have in the commit you are "fixing").
(2) Optional.  If you wanted to make changes other than commit
    log, do your edit here in the working tree.  When done, run
    "git diff HEAD" to make sure the changes are what you want
    the "fixed" commit to have.
(3) Run:
    $ git commit -c ORIG_HEAD
    If you made changes in (2) and have not done
    "git-update-index" on them, you may want to add '-a' there.
    If you are just redoing the log message you probably would
    not.
    This gives you the editor with the log message from the
    commit you undone in step (1).  Do your edit and exit the
    editor as usual.

Look at the output in "gitk HEAD ORIG_HEAD" to understand what happened. You just rewound a commit, and made a different commit.

Harder, more cumbersome case, is when you realize that you made a mistake a several commits ago. This is described in detail in Documentation/howto/revert-branch-rebase. Read it.

Previous: Kevin LeungNext: Tony Luck
Message 2 of 9 in “Edit log message after commit”
  1. Kevin LeungSep 29, 2005
  2. Junio C HamanoSep 29, 2005
  3. Tony LuckSep 29, 2005
  4. Brian GerstSep 29, 2005
  5. Kevin LeungSep 29, 2005
  6. Yasushi SHOJISep 29, 2005
  7. Junio C HamanoSep 30, 2005
  8. Catalin MarinasSep 29, 2005
  9. Kevin LeungSep 30, 2005

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.