threads / discuss / 17199

how to edit commit message in history

Subject: how to edit commit message in history

## tl;dr

4 messages between Jan 16, 2009 and Jan 16, 2009.

replies: 3people: 4as markdown or json

bill lam· Jan 16, 2009, 03:57 UTC · lore

I made some typos in commit messages, how to edit them without affecting everything else?

Thanks in advance.
-- 
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
唐詩311 無名氏  雜詩
    盡寒食雨草萋萋  著麥苗風柳映堤  等是有家歸未得  杜鵑休向耳邊啼
Jike Song· Jan 16, 2009, 04:09 UTC · re: bill lam · lore

Re: how to edit commit message in history

On Fri, Jan 16, 2009 at 11:57 AM, bill lam <cbill.lam@gmail.com> wrote:
> I made some typos in commit messages, how to edit them without
> affecting everything else?
>
> Thanks in advance.
say, it's commit HEAD~2 to be revised.
    git rebase -i HEAD~3
In your editor, you all see something like this:

pick db79377 2nd pick fa9ced8 3rd pick b842e49 4nd

# Rebase 1423d77..b842e49 onto 1423d77 # # Commands: # p, pick = use commit # e, edit = use commit, but stop for amending # s, squash = use commit, but meld into previous commit # # If you remove a line here THAT COMMIT WILL BE LOST. # However, if you remove everything, the rebase will be aborted. #

Now change "pick" to "edit" with your typo commit, save it and exit. You will see something like this:

$ git-rebase -i HEAD~3 Stopped at db79377... 2nd You can amend the commit now, with

        git commit --amend
Once you are satisfied with your changes, run
        git rebase --continue
Just follow the instructions.
-- 
Thanks,
Jike
thestar@fussycoder.id.au· Jan 16, 2009, 04:31 UTC · re: bill lam · lore

Re: how to edit commit message in history

You can't, that would default the whole point of git's sha1 hashes!

If you change a commit, you will change the sha1 hash of that commit, and every subsequent commit. There is no way around it.

Quoting bill lam <cbill.lam@gmail.com>:
Show 17 quoted lines
> I made some typos in commit messages, how to edit them without
> affecting everything else?
>
> Thanks in advance.
>
> --
> regards,
> ====================================================
> GPG key 1024D/4434BAB3 2008-08-24
> gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
> 唐詩311 無名氏  雜詩
>     盡寒食雨草萋萋  著麥苗風柳映堤  等是有家歸未得  杜鵑休向耳邊啼
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
Jakub Narebski· Jan 16, 2009, 11:18 UTC · re: bill lam · lore

Re: how to edit commit message in history

bill lam <cbill.lam@gmail.com> writes:
> I made some typos in commit messages, how to edit them without
> affecting everything else?

If it is last commit that you want to edit, and if you didn't publish this commit to soem public repository, you can simply use

  $ git commit --amend

If the commit is deeper in history, use "git rebase --interactive". If you published commit, you are out of luck.

See http://git.or.cz/gitwiki/GitTips
-- 
Jakub Narebski
Poland
ShadeHawk on #git

← back to recent threads