# Re: changing log entries

5 messages from 2006-12-13 to 2006-12-15. Participants: Shawn Pearce, Jakub Narebski, Andy Parkins, Jon Masters.
Thread: https://gitlist.dev/t/43316

## Jon Masters, 2006-12-13 23:08

Subject: changing log entries
Message-ID: <1166051281.1808.1.camel@jcm.boston.redhat.com>
URL: https://gitlist.dev/e/1166051281.1808.1.camel%40jcm.boston.redhat.com

```
Hi,

So I figured out that the problem with "Can't lock ref" was down to not
having set one of the scripts executable on the http server. Great.

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?

Jon.


```

## Jakub Narebski, 2006-12-13 23:22

Subject: Re: changing log entries
Message-ID: <elq1qk$4ie$2@sea.gmane.org>
URL: https://gitlist.dev/e/elq1qk%244ie%242%40sea.gmane.org
In-Reply-To: <1166051281.1808.1.camel@jcm.boston.redhat.com>

```
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?

See top two answers in http://git.or.cz/gitwiki/GitTips
-- 
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git


```

## Shawn Pearce, 2006-12-13 23:24

Subject: Re: changing log entries
Message-ID: <20061213232452.GE32568@spearce.org>
URL: https://gitlist.dev/e/20061213232452.GE32568%40spearce.org
In-Reply-To: <1166051281.1808.1.camel@jcm.boston.redhat.com>

```
Jon Masters <jcm@redhat.com> wrote:
> Hi,
> 
> So I figured out that the problem with "Can't lock ref" was down to not
> having set one of the scripts executable on the http server. Great.
> 
> 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 its the most recent commit on that branch, "git commit --amend".

Otherwise dump out the branch to patches with git format-patch,
amend the commit in question, then replay the patches with git am.

Or use StGIT to uncommit the changes, pop them off, fix the commit,
then repush the patches and recommit in StGIT.


Note that any of the above methods change the SHA1 of that commit
and every commit which follows it on that branch.  Consequently it
is generally considered to be impolite to edit commits without
warning which you have already published, as another person may be
basing their own work off that commit.

-- 

```

## Andy Parkins, 2006-12-14 10:37

Subject: Re: changing log entries
Message-ID: <200612141037.35061.andyparkins@gmail.com>
URL: https://gitlist.dev/e/200612141037.35061.andyparkins%40gmail.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

```

## Jakub Narebski, 2006-12-15 08:48

Subject: Re: changing log entries
Message-ID: <eltncn$te5$1@sea.gmane.org>
URL: https://gitlist.dev/e/eltncn%24te5%241%40sea.gmane.org
In-Reply-To: <200612141037.35061.andyparkins@gmail.com>

```
Andy Parkins wrote:

> 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

Theoretically you should do

$ git rebase --onto temp-edit-branch master^^ master

but thanks to automatic detection that patch is already applied the
above also should work. Well, unless you edit the commit so much
that git does not recognize it as the same commit...

> $ git branch -D temp-edit-branch
> 
>  * -- A' -- B' -- C' (master)
>   \
>    A -- B -- C

...in which case "git rebase temp-edit-branch master" would give you

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

-- 
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git


```
