将提交消息自动附加到在Git中提交的文件 [英] Append the commit message automatically to the file being committed in Git

查看:149
本文介绍了将提交消息自动附加到在Git中提交的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是在存储库中的每个文件末尾保存所有提交历史记录/消息的日志。我使用commit-msg钩子来获取提交消息,准备并将其附加到文件中。然而,我注意到,由于文件在升级后发生变化,git状态仍显示为已修改。这样做的正确方法是什么?

解决方案

虽然我同意奥利查尔斯沃斯的意见,你不应该这样做,实际上是可能的。这是一个简单的post-commit挂钩,它重写提交,将提交消息附加到文件changelog。

  if! test $ {GIT_BYPASS_POST_COMMIT + set} 
然后
export GIT_BYPASS_POST_COMMIT = 1

git show --format =%B -s>> changelog
git add changelog
git commit --amend -C HEAD
fi

如果你试试这个,我希望你很快就会发现它对于正常使用git并不会很好。最简单的例子是,如果你修改一个提交,你将会修改已经改变了 changelog 的提交,所以挂钩最终会复制提交信息。



您可以决定是否试图让这个工作成功,或者放弃它,但我建议后者。


My aim is to maintain a log of all the commit history/messages at the end of each file in my repository. I used the commit-msg hook to get the commit message, prepare it and append it to the file.

However, I notice that since the file changes after staging, git status still shows as modified. What is the proper way to do this?

解决方案

Although I agree with Oli Charlesworth's comments that you should not be doing this, it is actually possible. Here is a simple post-commit hook that rewrites the commit, appending the commit message to the file "changelog".

if ! test ${GIT_BYPASS_POST_COMMIT+set}
then
    export GIT_BYPASS_POST_COMMIT=1

    git show --format=%B -s >>changelog
    git add changelog
    git commit --amend -C HEAD
fi

If you try this, I expect you will quickly find that it does not play nice with normal use of git. The simplest example is that if you amend a commit, you will be amending the commit that already changes changelog, so the hook ends up duplicating the commit message.

It's up to you to say whether you want to make an attempt to get this to work, or just give up on it, but I recommend the latter.

这篇关于将提交消息自动附加到在Git中提交的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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