二丫讲梵 二丫讲梵
首页
  • 最佳实践
  • 迎刃而解
  • Nginx
  • Php
  • Zabbix
  • AWS
  • Prometheus
  • Grafana
  • CentOS
  • Systemd
  • Docker
  • Rancher
  • Ansible
  • Ldap
  • Gitlab
  • GitHub
  • Etcd
  • Consul
  • RabbitMQ
  • Kafka
  • MySql
  • MongoDB
  • OpenVPN
  • KVM
  • VMware
  • Other
  • ELK
  • K8S
  • LLM
  • Nexus
  • Jenkins
  • 随写编年
  • 家人物语
  • 追忆青春
  • 父亲的朋友圈
  • 电影音乐
  • 效率工具
  • 博客相关
  • Shell
  • 前端实践
  • Vue学习笔记
  • Golang学习笔记
  • Golang编程技巧
  • 学习周刊
  • Obsidian插件周刊
关于
友链
  • 本站索引

    • 分类
    • 标签
    • 归档
  • 本站页面

    • 导航
    • 打赏
  • 我的工具

    • 备忘录清单 (opens new window)
    • json2go (opens new window)
    • gopher (opens new window)
    • 微信MD编辑 (opens new window)
    • 国内镜像 (opens new window)
    • 出口IP查询 (opens new window)
    • 代码高亮工具 (opens new window)
  • 外站页面

    • 开往 (opens new window)
    • ldapdoc (opens new window)
    • HowToStartOpenSource (opens new window)
    • vdoing-template (opens new window)
GitHub (opens new window)

二丫讲梵

行者常至,为者常成
首页
  • 最佳实践
  • 迎刃而解
  • Nginx
  • Php
  • Zabbix
  • AWS
  • Prometheus
  • Grafana
  • CentOS
  • Systemd
  • Docker
  • Rancher
  • Ansible
  • Ldap
  • Gitlab
  • GitHub
  • Etcd
  • Consul
  • RabbitMQ
  • Kafka
  • MySql
  • MongoDB
  • OpenVPN
  • KVM
  • VMware
  • Other
  • ELK
  • K8S
  • LLM
  • Nexus
  • Jenkins
  • 随写编年
  • 家人物语
  • 追忆青春
  • 父亲的朋友圈
  • 电影音乐
  • 效率工具
  • 博客相关
  • Shell
  • 前端实践
  • Vue学习笔记
  • Golang学习笔记
  • Golang编程技巧
  • 学习周刊
  • Obsidian插件周刊
关于
友链
  • 本站索引

    • 分类
    • 标签
    • 归档
  • 本站页面

    • 导航
    • 打赏
  • 我的工具

    • 备忘录清单 (opens new window)
    • json2go (opens new window)
    • gopher (opens new window)
    • 微信MD编辑 (opens new window)
    • 国内镜像 (opens new window)
    • 出口IP查询 (opens new window)
    • 代码高亮工具 (opens new window)
  • 外站页面

    • 开往 (opens new window)
    • ldapdoc (opens new window)
    • HowToStartOpenSource (opens new window)
    • vdoing-template (opens new window)
GitHub (opens new window)
  • 最佳实践

  • 迎刃而解

  • Nginx

  • Php

  • Zabbix

  • AWS

  • Prometheus

  • Grafana

  • Loki

  • CentOS

  • Supervisord

  • Systemd

  • Docker

  • Docker-Compose

  • Rancher

  • Ansible

  • OpenLdap

  • GitLab

    • Gitlab简单部署
    • Gitlab备份以及恢复
    • 配置Gitlab提交代码的钉钉通知
    • 汉化Gitlab-10-1-0
    • 如何迁移一个仓库到新的Gitlab
    • Gitlab忘记root密码怎么办
    • 通过命令行git log获取各种提交信息
    • 使用curl批量在分组内创建项目
    • git更改前一次commit内容并提交到master
    • git配置github与gitlab推送时指定不同用户与邮箱
  • GitHub

  • Etcd

  • Consul

  • RabbitMQ

  • Kafka

  • Mysql

  • MongoDB

  • OpenVPN

  • Kvm

  • VMware

  • 配置文件详解

  • Other

  • 运维观止
  • GitLab
二丫讲梵
2020-12-24

通过命令行git log获取各种提交信息

文章发布较早,内容可能过时,阅读注意甄别。

git log 命令可以提供给我们很多代码提交的信息,通过一些格式化,我们能够更加优雅的得到对应的信息:

  • git log --pretty=format:"%h"

git 用各种 placeholder 来决定各种显示内容:

  • %H: commit hash
  • %h: 缩短的 commit hash
  • %T: tree hash
  • %t: 缩短的 tree hash
  • %P: parent hashes
  • %p: 缩短的 parent hashes
  • %an: 作者名字
  • %aN: mailmap 的作者名字 (.mailmap 对应,详情参照git-shortlog(1) (opens new window)或者git-blame(1) (opens new window))
  • %ae: 作者邮箱
  • %aE: 作者邮箱 (.mailmap 对应,详情参照git-shortlog(1) (opens new window)或者git-blame(1) (opens new window))
  • %ad: 日期 (–date= 制定的格式)
  • %aD: 日期, RFC2822 格式
  • %ar: 日期, 相对格式 (1 day ago)
  • %at: 日期, UNIX timestamp
  • %ai: 日期, ISO 8601 格式
  • %cn: 提交者名字
  • %cN: 提交者名字 (.mailmap 对应,详情参照git-shortlog(1) (opens new window)或者git-blame(1) (opens new window))
  • %ce: 提交者 email
  • %cE: 提交者 email (.mailmap 对应,详情参照git-shortlog(1) (opens new window)或者git-blame(1) (opens new window))
  • %cd: 提交日期 (–date= 制定的格式)
  • %cD: 提交日期, RFC2822 格式
  • %cr: 提交日期, 相对格式 (1 day ago)
  • %ct: 提交日期, UNIX timestamp
  • %ci: 提交日期, ISO 8601 格式
  • %d: ref 名称
  • %e: encoding
  • %s: commit 信息标题
  • %f: sanitized subject line, suitable for a filename
  • %b: commit 信息内容
  • %N: commit notes
  • %gD: reflog selector, e.g., refs/stash@{1}
  • %gd: shortened reflog selector, e.g., stash@{1}
  • %gs: reflog subject
  • %Cred: 切换到红色
  • %Cgreen: 切换到绿色
  • %Cblue: 切换到蓝色
  • %Creset: 重设颜色
  • %C(…): 制定颜色, as described in color.branch.* config option
  • %m: left, right or boundary mark
  • %n: 换行
  • %%: a raw %
  • %x00: print a byte from a hex code
  • %w([[,[,]]]): switch line wrapping, like the -w option of git-shortlog(1).

img

当前在 Jenkins 的应用中,通过如下方式,在项目拉完代码之后对一些信息进行了提取:

// 提交ID
env.COMMIT_ID   = sh(script: 'git log --pretty=format:%h',  returnStdout: true).trim()
// 提交者
env.COMMIT_USER = sh(script: 'git log --pretty=format:%an', returnStdout: true).trim()
// 提交时间
env.COMMIT_TIME = sh(script: 'git log --pretty=format:%ai', returnStdout: true).trim()
// 提交信息
env.COMMIT_INFO = sh(script: 'git log --pretty=format:%s',  returnStdout: true).trim()
1
2
3
4
5
6
7
8

这个信息可以在通知,以及更改构建信息都可以用到,便于运维开发测试一起核对。

微信 支付宝
#gitlab
上次更新: 2024/07/04, 22:40:37
Gitlab忘记root密码怎么办
使用curl批量在分组内创建项目

← Gitlab忘记root密码怎么办 使用curl批量在分组内创建项目→

最近更新
01
记录二五年五一之短暂回归家庭
05-09
02
学习周刊-总第210期-2025年第19周
05-09
03
学习周刊-总第209期-2025年第18周
05-03
更多文章>
Theme by Vdoing | Copyright © 2017-2025 | 点击查看十年之约 | 浙ICP备18057030号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式