我想使用 powershell 查找特定檔案/路徑的提交歷史記錄。根據上次提交訊息,如果它被洗掉,我將呼叫一個已洗掉的函式。它呼叫一個 rest API 將它從 Azure 中洗掉,否則它將轉到下一步。
這是我想要做的
$commited_file_name = $([io.path]::GetFileNameWithoutExtension($_.Line)) #This gives Me the filename $path = $_.Line #This Gives me the complete Path. They change it dynamically based on the committed file in the Azure Devops Repo
通過使用以上幾行,我傳遞了以下 git 命令來獲取特定檔案的提交歷史記錄。我的大部分檔案都是 Json 檔案。
通過參考這兩個在 Git 中查找檔案何時被洗掉以及如何在專案提交歷史中查找已洗掉的檔案。因為我找不到如何通過 powershell 做到這一點。
這是我所做的。
#Tried to get the commit history using a Path
$commit_log = git log --full-history -1 [$path]
WriteDebug "Commit Log:$commit_log" #[However this is not returning anything ]
#Then tried to get the commit history using a Filename
$commit_file = git log --all --full-history -1 -- "**/$commited_file_name.json.*"
WriteDebug "Commit File history:$commit_file" #[This is also not returing anything]
#And it is failing at this point and invoked the DotheNextTask function even if the last commit of the file was deleted.
$filter_commit = $("$commit_file" | grep -c "Deleted")
if ("$filter_commit" -ne 0 ) {
Deletefile
}
else{
DotheNextTask
}
有什么我做錯了嗎?或者我在這里遺漏了什么。
uj5u.com熱心網友回復:
我已經更新了代碼并對其進行了測驗。現在它正在顯示輸出。
請注意,如果您使用的是 PowerShell,則必須對連字符進行轉義:git log '--' [檔案路徑]。
$commit_file = git log --all --full-history -1 $("**/$commited_file_name.*")
WriteDebug "Commit File history:$commit_file" #[Fetches previous commit history from all branches for that specific file]
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/373765.html
