Dmi*_*sev 6 git jira visual-studio-code
我们将Jira Issue #添加到提交消息中,以将更改与Jira Issue链接起来。由于问题编号是手动添加的,很容易出现人为错误。由于我们总是在git 分支中保存这个数字,所以提交消息可以有这个分支名称的默认值吗?可以通过VS 代码扩展或git 模板来完成吗?
我创建了这个名为prepare-commit-msg
我复制到.git/hooks
文件夹中的文件
#!/bin/bash
# Get the current branch name
current_branch=`git rev-parse --abbrev-ref HEAD`
# Search Jira ID in a pattern such a "feature/ABCD-123-my-feature"
id=$(echo $current_branch | sed -nE 's,[a-z]+/([A-Z]+-[0-9]+)-.+,\1,p')
# Only prepend if an ID was found in the current branch
if [[ ! -z $id ]]; then
# $1 is the name of the file containing the commit message
# Prepend "ABCD-123: "
sed -i.bak -E "1s/^/${id}: /" $1
fi
Run Code Online (Sandbox Code Playgroud)
要点如下:https://gist.github.com/raduchiriac/36b6269bebb75cfac7371acb1459fdcc
注意:您会发现许多解决方案使用sed -nr
,不幸的是,它在塞拉之后不再起作用。使用-E
小智 0
我建议您使用commit-msg
本地钩子和pre-receive
服务器钩子来达到您的目的。Git hooks是验证和修改存储库写入操作的脚本 - 您可能会在官方文档中熟悉它们:https ://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks
本地commit-msg
挂钩可以从分支中提取票证名称并将其附加到消息中(如果在那里尚未找到)。如果分支名称不满足命名要求,它甚至可以取消提交过程。
这种方法的主要缺点是,出于安全考虑,任何开发人员都应该手动放置本地挂钩,因此人们也可能会忘记或忽略这一点。因此,您还需要一个服务器端pre-receive
挂钩来拒绝推送的分支,无论新提交之一是否包含无效消息。
归档时间: |
|
查看次数: |
7674 次 |
最近记录: |