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

Viewed 385

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 Answers

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

Related