侧边栏壁纸
博主头像
恪晨博主等级

前端程序员

  • 累计撰写 140 篇文章
  • 累计创建 41 个标签
  • 累计收到 17 条评论

目 录CONTENT

文章目录
Git

如何获取git提交信息

恪晨
2024-02-20 / 0 评论 / 0 点赞 / 38 阅读 / 478 字 / 正在检测是否收录...

获取最后一次提交的版本短号

def commitId = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim();
echo "Git Commit ID: $commitId";

获取最后一次提交的时间20240220180122格式

def commitTime = sh(script: 'git show --pretty=format:"%cd" --date=format:"%Y%m%d%H%M%S" | head -1', returnStdout: true).trim();
echo "Git Commit time: $commitTime";

获取json文件中某个字段的值

def packageJSON = readJSON file: 'package.json';
def packageJSONVersion = packageJSON.version;
echo "version: $packageJSONVersion";

其他常见变量

%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).
0

评论区