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

Re: Editing a typo in the message given to "git commit"

From
Jakub Narębski <jnareb@gmail.com>
Date
Aug 22, 2016, 19:02 UTC
Message-ID
<8b0cf1e5-41c9-4b5a-0baf-4996c45d31ef@gmail.com>
In-Reply-To
<201608211519.u7LFJiMR090069@shell1.rawbw.com>
W dniu 21.08.2016 o 17:19, norm@dad.org pisze:
Show 10 quoted lines
> I am learning how to use git. I would like to know:
> 
> How can I correct a typo in the message I gave to an old "git commit"? I see
> that the typo occurs in exactly two files in .git:
> 
> .git/logs/refs/heads/master
> .git/logs/HEAD
> 
> /usr/bin/file says that they are both ASCII English text. So I could just
> hand edit them. But that seems somehow sacrilegious and might break git.

As the pathname suggests, those two files are only *logs*, to be more exact these store so called reflogs, which allow for example use @{1} for previous position of current branch in your local repository, or "git checkout -" (or "git checkout @{-1}") to go back to previous branch. You can edit them (just take care to not touch the rest of line / file), but it wouldn't change what is in your history, what 'git log' would show.

If the typo was in the last commit you have created, the simplest solution is to use 'git commit --amend' (assuming that you didn't 'git add' any files in meantime).

If it was something few commits back, you need to use 'git rebase --interactive', starting from the commit before the one you want to change. Then you need to change 'pick' to 'reword', as described in instruction sheet for interactive rebase.

P.S. Good source of finding answers is StackOverflow[1], and new (and in beta) StackOverflow Documentation

[1]: http://stackoverflow.com/questions/tagged/git [2]: http://stackoverflow.com/documentation/git

There is also #git channel on FreeNode[3]
[3]: ircs://chat.freenode.net:6697/git
Previous: Eric Wong
Message 4 of 4 in “Editing a typo in the message given to "git commit"”
  1. norm@dad.orgAug 21, 2016
  2. Pranit BauvaAug 21, 2016
  3. Eric WongAug 21, 2016
  4. Jakub NarębskiAug 22, 2016

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.