[英]Git log with version numbers
我正在嘗試生成一個自述文件,如下所示:
not released yet
30c9474 myname 2018-08-23 Feature 1337
v1.0.76
420368f myname 2018-08-22 Changed Jenkinsfile.groovy again
v1.0.75
be05539 myname 2018-08-16 Feature 2833
838c158 myname 2018-08-16 Fixed bug 9128
6fa061a myname 2018-08-14 Feature 8832
v1.0.74
21903f2 myname 2018-08-11 Some stuff
57f1a2f myname 2018-08-05 Changed Jenkinsfile.groovy
這就是我目前使用 jenkins 生成自述文件的方式:
node('master') {
def artifactConfig = [
version: '1.0.'+env.BUILD_NUMBER,
]
try {
// ######################################## Commit stage ######################################
stage('Create Changelog stage') {
// needs to be checked out again, because by default on master the sources are checkout out to ${WORKSPACE}@script in scripted pipeline
checkout scm
// the Changelog will be created here
sh 'git log $(git describe --tags --abbrev=0)..HEAD --pretty=format:"%d%h%x09%an%x09%ad%x09%s" --date=short --all | sed "s/^ *([^)]*)/\\n&\\n/;1i (not released yet)" > releasenotes.md'
sh 'git config --global --unset-all core.editor && git config --global core.editor $(which vim)'
sh 'git add releasenotes.md &&' +
'git tag -a version/' + artifactConfig.version + ' -m "Version version/' + artifactConfig.version + ' created" &&' +
'git commit -C HEAD --amend --no-edit &&' +
'git push -f origin version/' + artifactConfig.version
}
} catch (exception) {
currentBuild.result = 'FAILED'
throw exception
}
}
這會在版本化分支中創建一個自述文件。 我的問題是我不知道如何將該文件放在一起作為示例。 我想出的是如何生成一個自述文件,如:
30c9474 myname 2018-08-23 Feature 1337
420368f myname 2018-08-22 Changed Jenkinsfile.groovy again
be05539 myname 2018-08-16 Feature 2833
838c158 myname 2018-08-16 Fixed bug 9128
6fa061a myname 2018-08-14 Feature 8832
21903f2 myname 2018-08-11 Some stuff
57f1a2f myname 2018-08-05 Changed Jenkinsfile.groovy
編輯:這就是我的網絡圖的樣子: 在 jthill 的幫助下,我將 git 日志行更改為:
sh 'git log $(git describe --tags --abbrev=0)..HEAD --pretty=format:"%h%x09%an%x09%ad%x09%s" --date=short | sed "s/^ *([^)]*)/\\n&\\n/;1i (not released yet)" > releasenotes.md'
但現在的結果是這樣的:
(not released yet)
30c9474 myname 2018-08-23 Feature 1337
420368f myname 2018-08-22 Changed Jenkinsfile.groovy again
be05539 myname 2018-08-16 Feature 2833
838c158 myname 2018-08-16 Fixed bug 9128
6fa061a myname 2018-08-14 Feature 8832
21903f2 myname 2018-08-11 Some stuff
57f1a2f myname 2018-08-05 Changed Jenkinsfile.groovy
看起來更好,但它仍然不是我需要的。
您可以按照您需要的順序獲取您需要的數據
git log --date=short --pretty='%d%h %an %ad %s'
從那里它是用你最喜歡的工具處理的直接文本。 如果你不需要它太漂亮,通過管道
sed 's/^ *([^)]*)/\n&\n/;1i (not released yet)'
會做。
另一種方法是在git log --format=...
本身中包含該標簽/版本號。
Git 2.32(2021 年第二季度,7 年后)是可能的,“ git log --format=...
” ( man ) ”學習了“ %(describe)
”占位符。
請參閱René Scharfe ( rscharfe
) 的commit 9609972 、 commit 273c990 、 commit 09fe8ca (2021 年 2 月 28 日)和commit b081547 、 commit 15ae82d (2021 年 2 月 14 日) 。
(由Junio C gitster
合並-- gitster
--在commit 25f9326 ,2021 年 3 月 22 日)
pretty
: 添加 %(描述)建議人: Eli Schwartz
簽字人:René Scharfe
添加用於描述輸出的格式占位符。
通過實際調用
git describe
( man ) 來實現,既簡單又保證正確。
它旨在在具有屬性export-subst
和git archive
文件中與$Format:...$
一起使用。
它也可以與git log
( man )等一起使用,即使由於每次提交的 fork 會很慢。
和:
pretty
: 向%(describe)
添加合並和排除選項簽字人:René Scharfe
允許使用匹配和排除選項限制占位符
%(describe)
使用的標簽。
例如
以下命令使用官方版本標簽描述當前提交,不包括候選版本:$ git log -1 --format='%(describe:match=v[0-9]*,exclude=*rc*)'
pretty-formats
現在包含在其手冊頁中:
'%(describe[:options])':: 人類可讀的名稱,如
git describe
; 不可描述的提交的空字符串。describe
字符串后面可以跟一個冒號和零個或多個逗號分隔的選項。
- '
match=<pattern>
':只考慮匹配給定glob(7)
模式的標簽,不包括“refs/tags/”前綴。- '
exclude=<pattern>
':不考慮匹配給定glob(7)
模式的refs/tags/
,不包括“refs/tags/
”前綴。
警告:
pretty
:記錄多個 %(describe) 不一致報告人:Ævar Arnfjörð Bjarmason
簽字人:René Scharfe
每個
%(describe)
占位符都使用單獨的git describe
( man )調用進行擴展。
它們的輸出取決於當時存在的標簽,因此沒有一致性保證。
記錄這一事實。
pretty-formats
現在包含在其手冊頁中:
同時添加或刪除標簽時,描述可能會不一致。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.