简体   繁体   中英

Is there any way to get the latest commit date and time for every file in a GitHub repo?

I'm trying to build a tool that will allow me to compare the files in a (private) GitHub repo to the files on a web server.

I have figure out how to query v3 of the GH API to get back a list of all the files in a repo. Something like the following:

https://api.github.com/repos/username/repo-name/git/trees/sha?recursive=1

Where username , repo-name and sha are all variables that I know. This works fine. However, I need to then be able to get the last updated/modified timestamp for each file in the repo so that I can compare that to the last updated/modified timestamp of the associated files on the web server and know where the files in the master branch of the repo are newer than the files on the server.

Is there any way to do this? I've looked thoroughly through the GH API docs, but can't find any way to get the last updated/modified timestamps of files in the repo.

I suppose I could get the timestamp of each GH commit and see what files are in the commit, but for files that haven't been changed/committed in a long time, I'll have to go through too many commits to get the timestamp, which doesn't seem reasonable.

Any help/guidance is greatly appreciated.

I think it would be better to calculate the hashes of the source files on the web-server and compare the hashes instead of the timestamps.

You can get the git-hash of a source file like this:

git hash-object foo.php

If you do not have git installed on the web-server, you can use plain bash:

printf "blob $(wc -c < foo.php)\0$(cat foo.php)\n" | sha1sum

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM