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"
相关推荐
minji...1 小时前
linux 进程控制(一) (fork进程创建,exit进程终止)
linux·运维·服务器·c++·git·算法
系夏普1 小时前
Git 入门教程:初始化、修改与提交
git
laplaya1 小时前
Git 使用技巧
git
奶油松果2 小时前
git amend记录
git
庸俗今天不摸鱼3 小时前
git提交代码失败?本地代码被清空了?git代码丢了怎么办?三步帮你找回来
git
摇滚侠3 小时前
零基础小白自学 Git_Github 教程,Git 命令行操作3,笔记20
笔记·git·github
摇滚侠3 小时前
零基础小白自学 Git_Github 教程,GitLFS ,笔记21
笔记·git·github
lpfasd1234 小时前
Git之外的新选择?PlasticSCM深度对比与平台支持全解析
git
Cx330❀4 小时前
Git 入门指南:从 0 到 1 掌握版本控制
git·ubuntu·gitee·centos·github
爱凤的小光4 小时前
Git自我学习笔记
笔记·git·学习