我目前使用它來獲取我的提交哈希作為我的版本名稱。有沒有辦法獲取提交日期并將其添加到此:
def getCommitHash = { ->
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-parse', '--short', 'HEAD'
standardOutput = stdout
}
return stdout.toString().trim()
}
所以我得到這樣的東西:Version: 491a9d0, Date: 7-10-2022
uj5u.com熱心網友回復:
Git 提供了非常靈活的配置來格式化漂亮的列印。你可以使用不同的 git 命令:
git show -s --format="Version: %H, Date: %ci" HEAD
這將輸出如下內容:
Version: e6b12a79136b513cdca7fd12915dd422f8a3141e, Date: 2022-10-06 18:27:38 0100
或者在您的情況下,將其提供給正在運行的 git,
commandLine 'git', 'show', '-s', '--format="Version: %H, Date: %ci"', 'HEAD'
git show的檔案包含有關如何在格式選項中使用占位符的更多資訊。
uj5u.com熱心網友回復:
您可以將 git 命令替換為:
git log -1 --format="format:%h %cs"
格式字串的可能選項在git docs中給出。
%h獲取提交哈希的簡短版本,這相當于你現在得到rev-parse的%cs以短格式 (YYYY-MM-DD) 獲取提交日期
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/511120.html
標籤:安卓安卓工作室科特林
