Git日志-显示特定文件中最后一次更改的时间戳
为了获得特定文件中最后一次修改的时间戳,我尝试了以下方法:Git日志-显示特定文件中最后一次更改的时间戳,git,Git,为了获得特定文件中最后一次修改的时间戳,我尝试了以下方法: git日志-1--format=“%ai”-“abc/abc/abc/test_1203.sql” 上述命令的结果为空 我还尝试输出所有带有时间戳的更改,但我使用的命令中断了行,我希望使用“文件名”“时间戳” git log--diff filter=D--since=“3天前”--仅限姓名--pretty='format:%ai' 有什么办法让它工作吗 谢谢编辑-答案1 我不知道为什么,但Git命令现在在重新启动计算机后按预期运行(我
git日志-1--format=“%ai”-“abc/abc/abc/test_1203.sql”
上述命令的结果为空
我还尝试输出所有带有时间戳的更改,但我使用的命令中断了行,我希望使用“文件名”“时间戳”
git log--diff filter=D--since=“3天前”--仅限姓名--pretty='format:%ai'
有什么办法让它工作吗
谢谢编辑-答案1 我不知道为什么,但Git命令现在在重新启动计算机后按预期运行(我在Windows PC上)。下面的命令回答了我的问题:
git log -1 --format="%ai" -- "abc/abc/abc/test_1203.sql"
答案2 最后我做了一个变通方法来获得我想要的结果,基本上它包含了一个PowerShell脚本来解析从git返回的输出。这并不漂亮,我肯定有更好的方法,但它完成了任务
您的
.sql
文件是用git提交的吗?这也是第二个查询的另一个注释:git可能会为每个时间戳输出一个文档数组,而不仅仅是一个。您的目标是为它们中的每一个设置%ai
格式吗?您想在每个时间戳之间保留换行符吗?您好,谢谢您的关注。是的,.sql文件是用git提交的,我可以在问题中列出的第二个命令中返回文件名及其时间戳。--我想将数组每行的%ai格式化为一个表,类似于:file name | timestamp和下面的每个值。我不打算保留新词。谢谢你在窗户下吗?你能看到第一个命令的输出是否有帮助吗?
# get all deleted changes
$sqlDiffList= Git log --diff-filter=D --since="7 day ago" --name-only --pretty=format:%ai
#Helper
$timestamp =@()
$name =@()
$i = 0
# Loop through array and create two objects with matching IDs
foreach ($sqlDiff in $sqlDiffList) {
# New lines are determined by an empty string returned in the array, so we attribute a new ID for it.
if ($sqlDiff -eq '') {
$i += 1;
}
# Populate object with datetime values
if(($sqlDiff) -match "\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}")
{
$timestamp += New-Object -TypeName psobject -Property @{
id = $i;`
lastUpdate = $sqlDiff;`
filter = 'X'
}
# Populate object with file name
} else {
$name += New-Object -TypeName psobject -Property @{
id = $i;`
name = $sqlDiff;`
filter = 'X'
}
}
}
# Get rid of empty lines
$name = $name | Where-Object {$_.name -ne ''}
# Join the objects created above with the latest modification
foreach ($n in $name)
{
foreach ($t in $timestamp)
{
# decide whether to join
if ($n.id -eq ($t.id | Measure-Object -Maximum).Maximum)
{
# output a new object with the join result
New-Object PSObject -Property @{
name = $n.name;
lastUpdate = $t.lastUpdate;
filter = $t.filter;
};
}
}
}