1

I feel like I miss the forest for the trees... I just want to find out the date/time for the last update of a branch in a remote Git repository via command line.

For example, take https://github.com/StackExchange/stack-blog.git. If I view the branches for this repository on GitHub at https://github.com/StackExchange/stack-blog/branches, right now there is a line following the master branch that says:

Updated 2 months ago

That's the information I'm looking for. What's the git (or any) command one would use for that? Is this even possible without cloning the branch first?

finefoot
  • 9,914
  • 7
  • 59
  • 102
  • Would you mind checking of any of the answers helps you and if so accept it? If not, help us to help you – AnimiVulpis Jan 17 '18 at 18:45
  • I updated my answer for a new approach, but in general it is not possible to get the information you want without cloning (at least a part) of the repository. But I just read about `sparse-checkout` which might reduce the amount to download significantly. Will check and update my answer if it helps – AnimiVulpis Jan 18 '18 at 08:42

3 Answers3

2

Something like this should work:

git log -1 --format=%cd 
Derek Brown
  • 4,232
  • 4
  • 27
  • 44
  • @emmi474 you need a local clone. Accessing this data remotely isn't possible: https://stackoverflow.com/questions/20055398/is-it-possible-to-get-commit-logs-messages-of-a-remote-git-repo-without-git-clon – Derek Brown Oct 16 '17 at 10:08
1

For github specifically:

curl -s https://github.com/<user>/<repository>/tree/<branch> | sed -n -E 's/.*<relative-time datetime="([^"]+)".*/\1/p'

Explanation:

  • curl gets the html website containing the wished information
    • -s doesn't show any progress
  • sed
    • -n ignore non-matching lines
    • -E extended regex
    • 's/.*<relative-time datetime="([^"]+)".*/\1/p'
    • .*<relative-time datetime="([^"]+)".* Searches for the line containing the relative-time tag
    • \1 Replaces the match with the date of the last change
    • p In conjunction with -n will print only the match

Only downside: The date will not be in a relative format (because that seems to be computed by javascript after the side loads)


Different approach that works with every git repository:

Based on the answer to this question "Is it possible to get commit logs/messages of a remote git repo without git clone"

$ git clone --branch <branch name> --single-branch <repo url> --depth=1

This will download just a single revision of a single branch of the repository.

From this point on you can simply use:

$ git log -1 --format=%cd
AnimiVulpis
  • 2,670
  • 1
  • 19
  • 27
0

Use :

git log

And it'll show you all the previous updates. So you can checkout the commits by you or other people.

Neha
  • 3,456
  • 3
  • 14
  • 26