Is there a TFS Git API for getting file last modified date of files in a folder?

会有一股神秘感。 提交于 2021-02-19 08:29:57

问题


I am using TFS Git API to programmatically read data from my Git repository.

I have the requirement that I need to be able to get a folder from the git repository and list all of the files in it and their last modified timestamp.

I am using the items api and I am able to get the items in a folder with this request:

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?


回答1:


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



来源:https://stackoverflow.com/questions/62946929/is-there-a-tfs-git-api-for-getting-file-last-modified-date-of-files-in-a-folder

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!