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/2/ionic-framework/2.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提交-m“;打开编辑器_Git - Fatal编程技术网

如何强制;git提交-m“;打开编辑器

如何强制;git提交-m“;打开编辑器,git,Git,我正在为团队实现git模板提交消息。 我已经通过.git/hooks/prepare commit msghook by完成了 添加一行: cat.gitmessage”>>“$1” 此外,我还配置了以下功能: git config--local commit.template.gitmessage 好的,模板特性可以很好地工作,但只有在调用git commit时才能工作 不带-m标志 不幸的是,所有团队成员的工作流程都是: git add ... git commit -m "Some mes

我正在为团队实现git模板提交消息。 我已经通过
.git/hooks/prepare commit msg
hook by完成了 添加一行:

cat.gitmessage”>>“$1”

此外,我还配置了以下功能:

git config--local commit.template.gitmessage

好的,模板特性可以很好地工作,但只有在调用git commit时才能工作 不带
-m
标志

不幸的是,所有团队成员的工作流程都是:

git add ...
git commit -m "Some message"
问题:如何强制git始终打开编辑器来编辑消息,
即使在被
git commit-m…
命令调用时?

您也可以修改
commit msg
预钩子来实现这一点。例如,您可以检查提交消息中的行数(检查下面的示例);使用一些正则表达式检查模板是否受尊重;等等

#!/bin/bash

# Check if the number of lines is greater than 3
commit_msg_file="${1}"
minimum_lines=3
num_lines=$(wc -l "${commit_msg_file}" | cut -f1 -d' ')

if (( $num_lines < $minimum_lines )); then
    echo >&2 "Error!"
    exit 1
fi
#/bin/bash
#检查行数是否大于3
commit_msg_file=“${1}”
最小_线=3
num_line=$(wc-l“${commit_msg_file}”| cut-f1-d')
如果($num_行<$minimum_行));然后
echo>&2“错误!”
出口1
fi
检查和以供参考。

-e打开编辑器

git commit -m "message" -e

使用
-m
的全部意义在于,您可以跳过打开编辑器并在inlineI中定义消息。我将禁止它们直接推送到上游主机,并请求它们创建拉请求。如果提交消息不符合质量标准,请拒绝请求。您可能可以将模板保存在某个文件“template”中,然后运行“git commit-F template”,以便从该文件中获取提交消息。(这是您的解决方案的替代方案,但-m本身意味着您希望跳过编辑器)您可以使用只允许多行提交消息的预提交挂钩。这样,使用-m变得非常乏味:)(1)好吧,团队自动化的全部目的就是让它。。。自动的。另一种方法是通过电子邮件或口头要求所有团队成员遵守提交消息的新指示。(2) 我们仍然在没有审查的情况下直接推送到git服务器。