gpt4 book ai didi

git - 从 commit-msg hook 使用 Git 的提交消息清理模式

转载 作者:IT王子 更新时间:2023-10-29 00:54:34 26 4
gpt4 key购买 nike

git help commit说如下:

--cleanup=<mode>
This option determines how the supplied commit message should be
cleaned up before committing. The <mode> can be strip, whitespace,
verbatim, or default.

strip
Strip leading and trailing empty lines, trailing whitespace,
and #commentary and collapse consecutive empty lines.

whitespace
Same as strip except #commentary is not removed.

verbatim
Do not change the message at all.

default
Same as strip if the message is to be edited. Otherwise
whitespace.

我想从提交消息 hook 中确定要应用哪种清理模式(必要时正确使用 commit.cleanup config value)。 I run some validations on my commit messages我想确保我看到的是 Git 计划使用的确切内容。

或者,我会接受一种在清理后获取提交消息文本的方法(也许我可以欺骗 Git 为我清理它?)。这对我的用例非常有用,从那时起我就不必担心重新实现任何清理模式。

最佳答案

不幸的是,在当前(大概)的 git 源代码中,清理模式没有以任何方式传递给 Hook 。 --cleanup 的参数仅存储在(static,局部于 builtin/commit.c)变量 cleanup_mode 而不是导出(例如,作为参数或环境变量)到各种 Hook 。

(添加一个包含设置的环境变量应该很容易。如果你想自己试验一下,请参阅builtin/commit.c函数parse_and_validate_options;把在使用适当的参数调用 setenv() 时。)

关于git - 从 commit-msg hook 使用 Git 的提交消息清理模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16272849/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com