如何在不改变提交哈希的情况下改变git commit消息 [英] How to change git commit message without changing commit hash

查看:142
本文介绍了如何在不改变提交哈希的情况下改变git commit消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题并不确切,但我无法用单行表达。




  • 其实我知道如何改变git commit message像 here

  • 但我知道它总是改变SHA-1,我想避免它。



我只想 git-log 中的不同消息。我认为这可以用 git-notes 来完成,但我没有管理它。






解释:



我需要它来修复提交消息中的错误。我总是在那里写下包含与客户沟通的文档的名称(它看起来就像 T1234用foo替换foo )。通信往往会很长,所以我可以放松很多时间,直到我发现我在提交信息中被错误的文档名称误导。



使用 git-notes



它看起来像 git-notes 实际上按照这里。然而我始终使用

  git log --oneline 

所以我永远不会看到它。关于对用户进行git lie的评论:恕我直言,当这种情况发生时,仅当使用像这样的特殊开关 - replace-messages-by-notes 时,这是可以接受的。不是吗?因为我总是直接使用别名而不是直接使用 git log ,所以我可以在不输入太多内容的情况下获得所需内容。



你认为这是一个合理的功能请求,或者你会推荐另一个工作流程给我吗? 正如不同的人所指出的(例如 VonC非常有用的答案), git notes 确实是您正在寻找的机制。

  git log --oneline --show-notes $ b是否仅仅是将您的别名更改为以下内容? $ b  

假设您偶尔需要为提交添加备注,并且备注将在视觉上呈现如果你真的想替换每个提交的主题,如果注释存在,你可以总是创建一个脚本沿着以下行:



/ b>

  for c in $(git rev-list HEAD)
do
n = $(git notes show $
m = $(git show --oneline $ c | head -1)
if [-n$ n]
then
m = $ {m / * / $ n}
fi
echo $ m
完成

......但在我看来,这对我们来说收效甚微。


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?

解决方案

As various people have pointed out (e.g. in VonC's very useful answer), git notes really is the mechanism you're looking for. Is it not enough for you to change your alias to the following?

git log --oneline --show-notes

Presumably it's only occasionally that you'll have to add a note to a commit, and the notes will visually stand out in the output of that command.

If you really want to replace the subject of each commit if notes exist, you could always create a script along the lines of:

for c in $(git rev-list HEAD)
do
    n=$(git notes show $c 2> /dev/null)
    m=$(git show --oneline $c|head -1)
    if [ -n "$n" ]
    then
       m=${m/ */ $n}
    fi
    echo $m
done

... but that's a lot uglier for little gain, in my opinion.

这篇关于如何在不改变提交哈希的情况下改变git commit消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆