From: Kevin Leung <hidden> Date: 2016-06-15 22:42:07
Hi,
Is there any method to edit the log message after committed? I couldn't find any information in Documentation and in git mailing list.
Regards,
Kevin Leung
From: Tony Luck <hidden> Date: 2016-06-15 22:42:07
Is there any method to edit the log message after committed?
I couldn't find any information in Documentation and in git mailing list.
No. Once a git object is created it is immutable (since its name is the
hash of its contents). If you realise right after you make a commit that
you want to change the message, you would have to redo it ... use
git diff or git whatchanged to get the details and the diffs, then use
git reset to backup, and re-apply.
If you have made subsequent commits, then you'll have to back those
out and redo them too.
If you have published your tree, then it's better to live with the 'bad'
commit than try to re-write history.
-Tony
From: Brian Gerst <hidden> Date: 2016-06-15 22:42:07
Kevin Leung wrote:
Hi,
Is there any method to edit the log message after committed? I couldn't
find any information in Documentation and in git mailing list.
The commit must be at the head, or else you can't change it without
breaking the chain of following commits. If you are using Cogito, use
cg-admin-uncommit and then re-commit it. Otherwise, create a new commit
object for the same tree and parent(s) as the old commit, with the new
message. The new commit object is your new head.
--
Brian Gerst
From: Kevin Leung <hidden> Date: 2016-06-15 22:42:07
Thank you all of you. I was able to redo the commit.
But as Tony has pointed out. I would have needed to redo all the subsequent commits if I was to change non-HEAD commit message. What is the proper way of doing that? Is it the same as Documentation/howto/revert-branch-rebase.txt ?
One more question is that, how to use the git commit --reedit-message flag? According to Documentation/howto/rebase-and-edit.txt, I guess the meaning is to re-apply one commit to current HEAD?
At Thu, 29 Sep 2005 15:45:49 +0800,
Kevin Leung wrote:
But as Tony has pointed out. I would have needed to redo all the
subsequent commits if I was to change non-HEAD commit message. What
is the proper way of doing that? Is it the same as
Documentation/howto/revert-branch-rebase.txt ?
as pointed out by others, if the tree is already public, do revert.
otherwise, use git-cherry-pick and git-rebase might help. but it
might not be a good idea. (don't know)
to illustrate this, create the following tree
c
|
b
|
a
|
initial
git-init-db
echo hello > hello.c
git-update-index --add hello.c
git-commit -v -m 'initial'
echo a >> hello.c
git-commit -a -m 'add a'
echo b >> hello.c
git-commit -a -m 'add b'
echo c >> hello.c
git-commit -a -m 'add c'
say, you want to edit the commit message for 'add a'.
first, create new branch at where you wanna change the message
git checkout -b temp HEAD^^^ # hmm... HEAD^3 doesn't work
cherry pick the 'add a' commit but don't commit yet
git-cherry-pick -n master^^
commit the change with reediting the original commit log
git commit --reedit master^^
rebase the _master_ to temp
git-checkout master
git-rebase temp
I'm pretty sure that there is better way to do it and these should be
easy to be scripted.
my two cents,
--
yashi