Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
424 views
in Technique[技术] by (71.8m points)

history - How to change git commit message without changing commit hash

The title is not exact, but I can't express it better in a single line.

  • I actually know how to change git commit message like here.
  • But I know it always changes the SHA-1 too, which I want to avoid.

I only want to see a different message in git-log. I thought it could be done somehow using git-notes, but I haven't managed it.


Explanation:

I need it in order to fix errors in the commit messages. I always write there the name of a document containing my communication with the customer (it looks just like T1234 Replace foo by bar). The communication tends to be quite long, so I can loose a lot of time till I find out I was being mislead by wrong document name in the commit message.

Use of git-notes

It looks like git-notes in fact works as stated here. However I always use

git log --oneline

so I never see it. Concerning the comment about making git lie to the user: IMHO, this would be acceptable when this happened only when using a special switch like --replace-messages-by-notes, wouldn't it? As I always use an alias instead of using git log directly, I'd get what I want without typing a lot.

Do you think it's a reasonable feature request or would you recommend another workflow to me?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

git notes is the only way to have a different git log message (different than the commit message) without changing the SHA1, as mentioned in the "Notes to Self" article (from the original Aug. 2010 article).

A few remarks though:

  • Notes are organized by namespace, the default one being "commits".
  • Notes don't modify the commit message, they only add to it (which might be why git notes isn't working for you).
  • Notes aren't pushed by default, unless you specify explicitly the refspec for them (refs/notes/*)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...