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

Re: changing log entries

From
APAndy Parkins <andyparkins@gmail.com>
Date
Dec 14, 2006, 10:37 UTC
Message-ID
<200612141037.35061.andyparkins@gmail.com>
In-Reply-To
<1166051281.1808.1.camel@jcm.boston.redhat.com>
On Wednesday 2006 December 13 23:08, Jon Masters wrote:
> Anyway, now I would like to change an existing log entry to make it a
> bit cleaner (read: add a first line that's under 80 characters). What's
> the best way to change an existing log entry for a commit?
If it's HEAD you want to change:
 git-commit --amend

If it's not, it's a bit harder. You could pull each commit out as a patch and apply them again later after a git-reset. However, git has a tool for automating a lot of that: git-rebase. man git-rebase has some excellent examples.

 * -- A -- B -- C (master)
Let's say you want to edit A; make a new branch at A:
$ git branch temp-edit-branch master^^
 
 * -- A (temp-edit-branch)
       \
        B -- C (master)

Edit A with git-commit --amend. This makes a new A, A' that has the new commit message:

 * -- A' (temp-edit-branch)
  \
   A -- B -- C (master)

Then you switch to "master" and rebase master onto temp-edit-branch; you can then delete temp-edit-branch

$ git-checkout master $ git-rebase temp-edit-branch $ git branch -D temp-edit-branch

 * -- A' -- B' -- C' (master)
  \
   A -- B -- C

Note that A-B-C are now dangling commits; a git-prune would be needed to clean them out of the repository.

The important thing to realise is that you can never really edit a commit. The best you can do is reapply it. In this example, the fact that B' makes the same change as B is irrelevant - they are two separate commits.

Note: this is only workable if you haven't pushed this branch to another 
repository.  The other repository would retain the original A--B--C branch 
and you will get "won't fast forward" errors if you try to push the 
new "A'--B'--C'" branch.
Andy
-- 
Dr Andy Parkins, M Eng (hons), MIEE
Previous: Shawn PearceNext: Jakub Narebski
Message 4 of 5 in “changing log entries”
  1. Jon MastersDec 13, 2006
  2. Jakub NarebskiDec 13, 2006
  3. Shawn PearceDec 13, 2006
  4. Andy ParkinsDec 14, 2006
  5. Jakub NarebskiDec 15, 2006

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.