{"thread":{"id":"1970","subject":"Edit log message after commit","startedAt":"2005-09-29T02:28:39Z","lastAt":"2005-09-30T08:24:29Z","messageCount":9,"participants":["Kevin Leung","Junio C Hamano","Tony Luck","Brian Gerst","Catalin Marinas","Yasushi SHOJI"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"9446","messageId":"dhfjcu$36f$1@sea.gmane.org","threadId":"1970","inReplyTo":null,"subject":"Edit log message after commit","fromName":"Kevin Leung","fromEmail":"hysoka@gmail.com","sentAt":"2005-09-29T02:28:39Z","receivedAt":"2005-09-29T02:28:39Z","isPatch":false,"sender":{"key":"hysoka@gmail.com","avatar":null},"body":"Hi,\n\nIs there any method to edit the log message after committed? I couldn't find any information in Documentation and in git mailing list.\n\n\nRegards,\nKevin Leung\n"},{"id":"9447","messageId":"7vr7b8pl0n.fsf@assigned-by-dhcp.cox.net","threadId":"1970","inReplyTo":"dhfjcu$36f$1@sea.gmane.org","subject":"Re: Edit log message after commit","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-09-29T04:15:20Z","receivedAt":"2005-09-29T04:15:20Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Kevin Leung <hysoka@gmail.com> writes:\n\n> Is there any method to edit the log message after committed? I\n> couldn't find any information in Documentation and in git\n> mailing list.\n\nUndoing and re-committing can be done with the following\nrecipe.\n\nThere is a *big* *red* *warning*, though.  If you have already\nmade available the commit you are about to undo to others, and\nlater other people have made more commits on top of them,\nmerging their changes back to your repository would make the\ncommit history look a bit funny.  You could still do this\nwithout damaging the repository.  This warning only applies to\nthe shape of the commit graph.\n\nFirst, the easiest case.  Undoing and recommitting the latest\ncommit in the current branch.\n\n(1) Run \"git diff HEAD\" and make sure that your working tree\n    matches the latest commit you are about to undo.  Then:\n\n    $ git reset --soft HEAD^\n\n    This leaves the working tree intact (i.e. it still has what\n    you to have in the commit you are \"fixing\").\n\n(2) Optional.  If you wanted to make changes other than commit\n    log, do your edit here in the working tree.  When done, run\n    \"git diff HEAD\" to make sure the changes are what you want\n    the \"fixed\" commit to have.\n\n(3) Run:\n\n    $ git commit -c ORIG_HEAD\n\n    If you made changes in (2) and have not done\n    \"git-update-index\" on them, you may want to add '-a' there.\n    If you are just redoing the log message you probably would\n    not.\n\n    This gives you the editor with the log message from the\n    commit you undone in step (1).  Do your edit and exit the\n    editor as usual.\n\nLook at the output in \"gitk HEAD ORIG_HEAD\" to understand what\nhappened.  You just rewound a commit, and made a different\ncommit.\n\nHarder, more cumbersome case, is when you realize that you made\na mistake a several commits ago.  This is described in detail in\nDocumentation/howto/revert-branch-rebase.  Read it.\n"},{"id":"9448","messageId":"12c511ca050928211769e4bf8e@mail.gmail.com","threadId":"1970","inReplyTo":"dhfjcu$36f$1@sea.gmane.org","subject":"Re: Edit log message after commit","fromName":"Tony Luck","fromEmail":"tony.luck@gmail.com","sentAt":"2005-09-29T04:17:00Z","receivedAt":"2005-09-29T04:17:00Z","isPatch":false,"sender":{"key":"tony.luck@gmail.com","avatar":null},"body":"> Is there any method to edit the log message after committed?\n> I couldn't find any information in Documentation and in git mailing list.\n\nNo.  Once a git object is created it is immutable (since its name is the\nhash of its contents).  If you realise right after you make a commit that\nyou want to change the message, you would have to redo it ... use\ngit diff or git whatchanged to get the details and the diffs, then use\ngit reset to backup, and re-apply.\n\nIf you have made subsequent commits, then you'll have to back those\nout and redo them too.\n\nIf you have published your tree, then it's better to live with the 'bad'\ncommit than try to re-write history.\n\n-Tony\n"},{"id":"9454","messageId":"433B7459.3040307@didntduck.org","threadId":"1970","inReplyTo":"dhfjcu$36f$1@sea.gmane.org","subject":"Re: Edit log message after commit","fromName":"Brian Gerst","fromEmail":"bgerst@didntduck.org","sentAt":"2005-09-29T04:58:01Z","receivedAt":"2005-09-29T04:58:01Z","isPatch":false,"sender":{"key":"bgerst@didntduck.org","avatar":null},"body":"Kevin Leung wrote:\n> Hi,\n> \n> Is there any method to edit the log message after committed? I couldn't \n> find any information in Documentation and in git mailing list.\n\nThe commit must be at the head, or else you can't change it without \nbreaking the chain of following commits.  If you are using Cogito, use \ncg-admin-uncommit and then re-commit it.  Otherwise, create a new commit \nobject for the same tree and parent(s) as the old commit, with the new \nmessage.  The new commit object is your new head.\n\n--\n\t\t\t\tBrian Gerst\n"},{"id":"9467","messageId":"dhg5vl$9ac$1@sea.gmane.org","threadId":"1970","inReplyTo":"dhfjcu$36f$1@sea.gmane.org","subject":"Re: Edit log message after commit","fromName":"Kevin Leung","fromEmail":"hysoka@gmail.com","sentAt":"2005-09-29T07:45:49Z","receivedAt":"2005-09-29T07:45:49Z","isPatch":false,"sender":{"key":"hysoka@gmail.com","avatar":null},"body":"Thank you all of you. I was able to redo the commit.\n\nBut as Tony has pointed out. I would have needed to redo all the subsequent commits if I was to change non-HEAD commit message. What is the proper way of doing that? Is it the same as Documentation/howto/revert-branch-rebase.txt ?\n\nOne more question is that, how to use the git commit --reedit-message flag? According to Documentation/howto/rebase-and-edit.txt, I guess the meaning is to re-apply one commit to current HEAD?\n"},{"id":"9468","messageId":"tnxbr2ce0fo.fsf@arm.com","threadId":"1970","inReplyTo":"dhfjcu$36f$1@sea.gmane.org","subject":"Re: Edit log message after commit","fromName":"Catalin Marinas","fromEmail":"catalin.marinas@gmail.com","sentAt":"2005-09-29T08:35:23Z","receivedAt":"2005-09-29T08:35:23Z","isPatch":false,"sender":{"key":"catalin.marinas@gmail.com","avatar":null},"body":"Kevin Leung <hysoka@gmail.com> wrote:\n> Is there any method to edit the log message after committed? I\n> couldn't find any information in Documentation and in git mailing\n> list.\n\nAs the others said, a commit object is immutable but it can be\nreplaced with a new one and the path from HEAD changed. If you need to\ndo this often, have a look at StGIT. It allows you to create patches\nas git commit objects and indefinitely edit them (both file changes\nand commit information like log messages, author etc.).\n\nIn the latest snapshot, I also added a commit command to permanently\nstore the patches into the repository after which you won't be able to\nedit them anymore (that's useful for maintainers using StGIT, not only\ncontributors).\n\n-- \nCatalin\n"},{"id":"9481","messageId":"87br2bq2ot.wl@mail2.atmark-techno.com","threadId":"1970","inReplyTo":"dhg5vl$9ac$1@sea.gmane.org","subject":"Re: Edit log message after commit","fromName":"Yasushi SHOJI","fromEmail":"yashi@atmark-techno.com","sentAt":"2005-09-29T16:05:54Z","receivedAt":"2005-09-29T16:05:54Z","isPatch":false,"sender":{"key":"yashi@atmark-techno.com","avatar":"https://gravatar.com/avatar/4817e8703ac4379935834d87453faa9d0c94b9dc19d83fcc54c67875eb133e59?d=mp&s=160"},"body":"At Thu, 29 Sep 2005 15:45:49 +0800,\nKevin Leung wrote:\n> \n> But as Tony has pointed out. I would have needed to redo all the\n> subsequent commits if I was to change non-HEAD commit message. What\n> is the proper way of doing that? Is it the same as\n> Documentation/howto/revert-branch-rebase.txt ?\n\nas pointed out by others, if the tree is already public, do revert.\notherwise, use git-cherry-pick and git-rebase might help.  but it\nmight not be a good idea. (don't know)\n\nto illustrate this, create the following tree\n\nc\n|\nb\n|\na\n|\ninitial\n\n    git-init-db\n    echo hello > hello.c\n    git-update-index --add hello.c\n    git-commit -v -m 'initial'\n    echo a >> hello.c\n    git-commit -a -m 'add a'\n    echo b >> hello.c\n    git-commit -a -m 'add b'\n    echo c >> hello.c\n    git-commit -a -m 'add c'\n\nsay, you want to edit the commit message for 'add a'.\n\nfirst, create new branch at where you wanna change the message\n\n    git checkout -b temp HEAD^^^   # hmm... HEAD^3 doesn't work\n\ncherry pick the 'add a' commit but don't commit yet\n\n    git-cherry-pick -n master^^\n\ncommit the change with reediting the original commit log\n\n    git commit --reedit master^^\n\nrebase the _master_ to temp\n\n    git-checkout master\n    git-rebase temp\n\nI'm pretty sure that there is better way to do it and these should be\neasy to be scripted.\n\nmy two cents,\n--\n          yashi\n"},{"id":"9539","messageId":"dhir4a$3qf$1@sea.gmane.org","threadId":"1970","inReplyTo":"tnxbr2ce0fo.fsf@arm.com","subject":"Re: Edit log message after commit","fromName":"Kevin Leung","fromEmail":"hysoka@gmail.com","sentAt":"2005-09-30T07:58:59Z","receivedAt":"2005-09-30T07:58:59Z","isPatch":false,"sender":{"key":"hysoka@gmail.com","avatar":null},"body":"Thanks Yashi and Catalin for the pointers. The information is exactly what\nI was looking for. :-)\n"},{"id":"9541","messageId":"7vfyrn6k02.fsf@assigned-by-dhcp.cox.net","threadId":"1970","inReplyTo":"87br2bq2ot.wl@mail2.atmark-techno.com","subject":"Re: Edit log message after commit","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-09-30T08:24:29Z","receivedAt":"2005-09-30T08:24:29Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Yasushi SHOJI <yashi@atmark-techno.com> writes:\n\n> first, create new branch at where you wanna change the message\n>\n>     git checkout -b temp HEAD^^^   # hmm... HEAD^3 doesn't work\n\nBecause it should be spelled HEAD~3.  HEAD^3 is \"the third\nparent of HEAD\" and usually does not exist, unless you are\ntalking about an Octopus merge of three or more branches.\n"}]}