【发布时间】:2022-01-10 09:18:18
【问题描述】:
我想使用 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 文件。
通过引用这两个Find when a file was deleted in Git 和How to find a deleted file in the project commit history。因为我找不到如何通过 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
}
有什么我做的不对吗?还是我在这里遗漏了什么。
【问题讨论】:
-
有人可以解释我做错了什么以及我应该做什么,以便通过 PowerShell 获取特定文件的 git 提交信息。在这里,我将 PowerShell 变量作为参数值传递给 git 命令,但它什么也没返回。
标签: git powershell git-log