是否有一个TFS Git API,用于获取文件夹中文件的文件最后修改日期? [英] Is there a TFS Git API for getting file last modified date of files in a folder?
问题描述
我正在使用TFS Git API以编程方式从我的Git存储库中读取数据.
我要求我需要能够从git存储库中获取一个文件夹,并列出其中的所有文件及其上次修改的时间戳.
我正在使用项目api,并且可以通过以下请求将这些项目保存在文件夹中:
我看不到有REST API可以返回时间戳.相反,您可以将存储库克隆到本地,然后使用以下命令输出时间戳:
git log -1 --pretty ="format:%ci"-路径
要输出带有时间戳的所有文件,请尝试以下脚本:
git ls-tree -r-仅名称HEAD |在读取文件名时;做echo"$(git log -1 --format ="%ci-$ filename)$ filename";完毕
更多示例,请检查案例https://docs.microsoft.com/en-us/rest/api/azure/devops/git/items/list?view=azure-devops-rest-5.1
For example:
GET https://dev.azure.com/fabrikam/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/items?scopePath=/MyWebSite/MyWebSite/Views&recursionLevel=Full&includeContentMetadata=true&api-version=5.1
This is able to get the item URLs, but has no way to include timestamps.
So I do not think this api will work.
Is there some other api that I need to call in order to get this information?
I don't see there is a REST API to return the timestamps. Instead, you can clone the repo to local, and use the following command to output the timestamps:
git log -1 --pretty="format:%ci" -- path
To output all files with timestamps, try the following script:
git ls-tree -r --name-only HEAD | while read filename; do
echo "$(git log -1 --format="%ci" -- $filename) $filename"
done
More examples, please check case https://serverfault.com/questions/401437/how-to-retrieve-the-last-modification-date-of-all-files-in-a-git-repository
这篇关于是否有一个TFS Git API,用于获取文件夹中文件的文件最后修改日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!