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

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


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

文章目录

1.操作


2.commit-msg文件

bash 复制代码
#!/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"
相关推荐
Merrick3 小时前
git撤销第一次commit
git
艾莉丝努力练剑5 小时前
【Git:基本操作】深度解析Git:从初始Git到熟悉基本操作
大数据·linux·c++·人工智能·git·gitee·指令
大白要努力!6 小时前
将Git项目的所有远程分支打包成压缩包文件
git
牧羊人_myr6 小时前
Git指令集
git
边疆.8 小时前
【Linux】版本控制器Git和调试器—gdb/cgdb的使用
linux·服务器·git·gdb调试·cgdb
安冬的码畜日常17 小时前
【JUnit实战3_22】 第十三章:用 JUnit 5 做持续集成(下):Jenkins + JUnit 5 + Git 持续集成本地实战演练完整复盘
git·测试工具·ci/cd·jenkins·集成测试·持续集成·junit5
wxxka19 小时前
git使用
开发语言·git
舒一笑20 小时前
用数据照亮成长之路:PandaCoder Git 统计工具窗口
git·后端·intellij idea
测试修炼手册1 天前
[测试工具] 如何把离线的项目加入成为git项目的新分支
git