Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使git预提交行为依赖于提交消息?_Git_Commit_Pre Commit Hook_Commit Message - Fatal编程技术网

如何使git预提交行为依赖于提交消息?

如何使git预提交行为依赖于提交消息?,git,commit,pre-commit-hook,commit-message,Git,Commit,Pre Commit Hook,Commit Message,我知道要让git在提交之前检查提交消息,可以实现hooks/commit msg。但是现在想象一下,您希望让钩子/pre-commit脚本根据提交消息的不同行为的情况 例如(在非常宽松的环境中),您可能希望检查提交消息中是否有[nocheck]标记,它总是让您的提交检查通过 或者,在更严格的环境中,您可能希望对每个文件都进行注释(并因此单独列出) 或者,您可能希望对照相关文件检查票据ID 等等 除了在commit msg中执行实际的签入(这似乎违反直觉)之外,还有其他方法可以实现这一点吗 但是现

我知道要让git在提交之前检查提交消息,可以实现
hooks/commit msg
。但是现在想象一下,您希望让
钩子/pre-commit
脚本根据提交消息的不同行为的情况

例如(在非常宽松的环境中),您可能希望检查提交消息中是否有
[nocheck]
标记,它总是让您的提交检查通过

或者,在更严格的环境中,您可能希望对每个文件都进行注释(并因此单独列出)

或者,您可能希望对照相关文件检查票据ID

等等

除了在commit msg中执行实际的签入(这似乎违反直觉)之外,还有其他方法可以实现这一点吗

但是现在设想一种情况,您想让钩子/预提交脚本根据提交消息的不同行为

这是不可能的,因为触发时没有提交消息

pre-commit
钩子首先运行,甚至在您键入提交消息之前


除了执行实际的签入
commit msg
(这似乎违反直觉)之外,还有什么方法可以实现这一点

这样做的方法正是使用
commit msg

commit msg
hook接受一个参数,该参数也是包含当前提交消息的临时文件的路径。如果此脚本退出非零,Git将中止提交过程,因此您可以在允许提交之前使用它验证项目状态或提交消息

但是现在设想一种情况,您想让钩子/预提交脚本根据提交消息的不同行为

这是不可能的,因为触发时没有提交消息

pre-commit
钩子首先运行,甚至在您键入提交消息之前


除了执行实际的签入
commit msg
(这似乎违反直觉)之外,还有什么方法可以实现这一点

这样做的方法正是使用
commit msg

commit msg
hook接受一个参数,该参数也是包含当前提交消息的临时文件的路径。如果此脚本退出非零,Git将中止提交过程,因此您可以在允许提交之前使用它验证项目状态或提交消息