我有一個裝滿檔案的檔案夾,我想獲取每個檔案的上次 git 更新的時間戳。
我想在 Gradle 任務中獲得這些。
我用 GrGit 嘗試了以下操作:
def git = org.ajoberstar.grgit.Grgit.open dir:project.rootDir
task showGit() {
doFirst {
file( "$project.rootDir/src/main/java/some/folder" ).listFiles().each{ f ->
git.log( includes:[ 'HEAD' ], paths:[ f.name ] ).each{
println "$f.name -> Author: $it.author.name - Date: ${it.date.format( 'dd.MM.yyyy HH:mm' )}"
}
}
}
}
但它什么也不列印。
如果我省略paths這樣的:
task showGit() {
doFirst {
git.log( includes:[ 'HEAD' ] ).each{
println "Author: $it.author.name - Date: ${it.date.format( 'dd.MM.yyyy HH:mm' )}"
}
}
}
它列印整個目錄的所有提交資訊。
如何獲取每個檔案的時間戳?
uj5u.com熱心網友回復:
事實證明這很容易。
受到如何在 Git 中獲取一堆檔案的最后提交日期的啟發?我整理了自己的 GrGit 任務:
def git = org.ajoberstar.grgit.Grgit.open dir:project.rootDir
task lastGitUpdated() {
doFirst {
int base = project.rootDir.toURI().toString().size()
def dates = file( "$project.rootDir/src/main/java/some/dir" ).listFiles().collect{
git.log( includes:[ 'HEAD' ], paths:[ it.toURI().toString().substring( base ) ], maxCommits:1 )[ 0 ].date
}
}
}
它就像一個魅力!
唯一有點令人失望的是,在一個包含 ~150 個檔案的目錄上的任務需要 ~2 分鐘才能完成......
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/332857.html
上一篇:致命:無法訪問“https://xxxx.git/”:服務器證書驗證失敗。CAfile:/etc/ssl/certs/ca-certificates.crtCRLfile:無
