{"thread":{"id":"33723","subject":"How do I modify the commit message (not the topmost one) of a git commit?","startedAt":"2013-05-04T06:31:26Z","lastAt":"2013-05-04T07:59:23Z","messageCount":2,"participants":["Norah Jones","Johan Herland"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"216402","messageId":"abcd1234abc123ab12a0000000345000020000004001@gmail.com","threadId":"33723","inReplyTo":null,"subject":"How do I modify the commit message (not the topmost one) of a git commit?","fromName":"Norah Jones","fromEmail":"nh.jones01@gmail.com","sentAt":"2013-05-04T06:31:26Z","receivedAt":"2013-05-04T06:31:26Z","isPatch":false,"sender":{"key":"nh.jones01@gmail.com","avatar":null},"body":"Hi, \n\nI did a series of commits and now I find one of my commit (not the topmost one) has an incorrect commit message. How can I change that specific one? I believe \"git commit --amend\" works only for the last commit.\n\n\nThanks,\nNorah Jones\n"},{"id":"216405","messageId":"CALKQrgcN06Y0dVrAX=yNPjneZymFo2SMq_ymz52Qs+_GgMD3gg@mail.gmail.com","threadId":"33723","inReplyTo":"abcd1234abc123ab12a0000000345000020000004001@gmail.com","subject":"Re: How do I modify the commit message (not the topmost one) of a git commit?","fromName":"Johan Herland","fromEmail":"johan@herland.net","sentAt":"2013-05-04T07:59:23Z","receivedAt":"2013-05-04T07:59:23Z","isPatch":false,"sender":{"key":"johan@herland.net","avatar":"https://avatars.githubusercontent.com/u/547031?v=4"},"body":"On Sat, May 4, 2013 at 8:31 AM, Norah Jones <nh.jones01@gmail.com> wrote:\n> Hi,\n>\n> I did a series of commits and now I find one of my commit (not the topmost one) has an incorrect commit message. How can I change that specific one? I believe \"git commit --amend\" works only for the last commit.\n\nTrue. Be aware that \"git commit --amend\" and the rebasing shown below\namounts to rewriting history, which is fine when it's your own local\nhistory, but if you've already shared the commits you are changing,\nthen you're forcing your collaborators to rebase their own work on top\nof your rewritten history.\n\nThat said, here's how to do a rebase to change a specific commit message:\n\n0. Make sure you have a clean worktree. \"git stash\" any uncommitted changes.\n\n1. Identify the commit you want to change, e.g. by using something\nlike HEAD~5 (for the 5th last commit on your current branch), or by\nthe 40-character commit id.\n\n2. \"git rebase -i $commit^\", where $commit is the commit you\nidentified above, and the trailing caret \"^\" is important. (rebase\nworks on a range of commits, and you want to start the rebase based on\nthe parent of the commit you wish to change).\n\n3. The rebase command will open your text editor with a list of your\ncommits, from the one you'd like to change, to your most recent\ncommit. Each commit is prefixed with the word \"pick\", which indicates\nthat rebase will replay that commit without any changes. You want to\nchange the commit message for the first commit in this list, so on the\nfirst line, change the \"pick\" into \"reword\". Save and exit the editor.\n\n4. Rebase will now start replaying the commits from your list. The\nfirst thing that will happen, is that it will reopen your text editor\nwith the commit message for the commit you want to change. Edit the\ncommit message to your liking, and save and exit the editor.\n\n5. Rebase will then replay all the following commits until the last\ncommit is done, and you're \"back\" where you were when you started the\nrebase. Since you did nothing more than change a commit message, you\nwill not get any conflicts during the rebase.\n\n6. If you stashed some uncommitted changes in step #0, you might want\nto un-stash them now: \"git stash pop\"\n\n\nHope this helps,\n\n...Johan\n\n-- \nJohan Herland, <johan@herland.net>\nwww.herland.net\n"}]}