GIT | git提交注释自动添加信息头

GIT | git提交注释自动添加信息头


时间:2024年9月6日10:20:11

1.操作

在这里插入图片描述


在这里插入图片描述

2.commit-msg文件

在这里插入图片描述

#!/bin/sh
#
# An example hook script to check the commit log message.
# Called by "git commit" with one argument, the name of the file
# that has the commit message.  The hook should exit with non-zero
# status after issuing an appropriate message if it wants to stop the
# commit.  The hook is allowed to edit the commit message file.
#
# To enable this hook, rename this file to "commit-msg".

# Uncomment the below to add a Signed-off-by line to the message.
# Doing this in a hook is a bad idea in general, but the prepare-commit-msg
# hook is more suited to it.
#
# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"

# This example catches duplicate Signed-off-by lines.

####test "" = "$(grep '^Signed-off-by: ' "$1" |
####     sort | uniq -c | sed -e '/^[   ]*1[    ]/d')" || {
####    echo >&2 Duplicate Signed-off-by lines.
####    exit 1
####}


# 获取当前变更号(变更号存放在根目录version文件内,具体位置根据自己情况)
# 每个分支都有独立且固定的系统变更号,所以此处以文件格式存放在代码目录
# 合并的时候可能有冲突,处理一次就好
#version=$(head -n +1 version)
# 获取当前分支
line=$(head -n +1 .git/HEAD)
#branch=${line##*/}
branch=$(git rev-parse --abbrev-ref HEAD)

# 获取当前提交的日期
date_time=$(date +%Y%m%d)
# 获取当前分支中的提交数
commit_count=$(git rev-list --count HEAD)
commit_count=$((commit_count + 1))

# 设置用户名
#name=flyer
commit=[" "${branch}" "]" "#${date_time}-${commit_count}#" "$(cat $1)
echo "$commit" > "$1"
  • 5
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值