【问题标题】:Git commit message validationGit 提交消息验证
【发布时间】:2019-10-25 16:31:10
【问题描述】:

我的提交信息将采用以下格式:

ANDROID-123 #commit Your commit message

ANDROID- 是固定关键字。

有什么建议吗?

【问题讨论】:

标签: git commit


【解决方案1】:

Git 挂钩是在 git 工作流程的某些阶段自动运行的脚本。有一个commit-msg git 挂钩,用于在提交过程中检查或更改提交消息。有关详细信息,请参阅git scm documentation

【讨论】:

    【解决方案2】:

    您可以使用 gitlabhook,例如 pre-receive 挂钩,您将在其中为您的提交消息定义一个正则表达式,然后检查新的提交消息是否像您预定义的正则表达式。 它会是这样的:

    REGEX="Your regex"
    
    while read oldrev newrev refname ; do
    #Validate commit message format
      for COMMIT in `git rev-list $oldrev..$newrev`;
      do
        MESSAGE=`git cat-file commit $COMMIT | sed '1,/^$/d'`       
        if [[ $MESSAGE =~ $REGEX ]]; then
          echo ""
        else 
          echo -e "Error Message" >&2
          exit 1
        fi
      done
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-21
      • 2011-09-07
      • 2021-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-15
      相关资源
      最近更新 更多