1

I need to get the date of the last commit (in seconds) from the remote repository without cloning it, and I need to do this with the basic git commands.

I can get the date of the last commit of the local repository in seconds using git log command, but I did not find how to do the same with the remote repository without cloning it.

git log -1 --format=%ct

I work in bash.

How can I do that?

Maslinin
  • 61
  • 5
  • 1
    Would https://stackoverflow.com/a/65464092/14637 be an acceptable workaround? It still creates a clone, but only downloads the latest commit on the default branch. – Thomas Apr 15 '22 at 08:42
  • No, unfortunately it doesn't fit. I need to find out the date without cloning the repository. – Maslinin Apr 15 '22 at 09:06
  • Why though? If you have a `git` executable and access to the remote (which you do), and have some writable temporary disk space (which you likely do), then you have everything you need to create a shallow clone. – Thomas Apr 15 '22 at 09:41
  • I write a script that should download only those repositories that have been changed since some time, so cloning is not allowed – Maslinin Apr 15 '22 at 09:52
  • 1
    You can't (quite). What you *can* do, depending on the hosting server involved, is get them to run `git archive` for you, download the resulting archive, and look at the file timestamps in that archive. The file timestamps in the archive are derived from the commit you've archived. But you're going about this all wrong in the first place. Don't look at the *date*. Look at the *commit hash*. – torek Apr 15 '22 at 10:03
  • @torek It's a pity... Well, thanks for the help! – Maslinin Apr 15 '22 at 11:19
  • I'll also note that if you have sufficient control on the host server, you can write something that answers a query from the client and passes the desired information back, by running the appropriate Git commands *on* the server and extracting the information. The reason for suggesting `git archive` is that you can invoke it from the client: it's pretty standard for a hosting server to support that directly, and common hosting sites like GitHub allow it. – torek Apr 16 '22 at 00:13

0 Answers0