How to find a Revisionnr. of a Commit

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
User avatar
bernd
Posts: 10824
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

How to find a Revisionnr. of a Commit

Postby bernd » Mon Jan 06, 2014 10:41 pm

How do I get the revision number of a commit? As an example may the number of the following commit

https://github.com/FreeCAD/FreeCAD_sf_m ... 520e05e9e2

It should be around 2600
wmayer
Site Admin
Posts: 16465
Joined: Thu Feb 19, 2009 10:32 am

Re: How to find a Revisionnr. of a Commit

Postby wmayer » Tue Jan 07, 2014 10:34 am

Unlike Subversion git does not work with revision numbers but with sha1 values. To extract some kind of revision number which humans understand better we count the number of newlines of all listed sha1 values. So, to get this information you have to:

Code: Select all

git rev-list <sha1> | wc -l
which in your case is:

Code: Select all

git rev-list f654c632ba9366ba2527284424469d520e05e9e2 | wc -l
which gives you 2655
User avatar
bernd
Posts: 10824
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: How to find a Revisionnr. of a Commit

Postby bernd » Tue Jan 07, 2014 12:10 pm

wmayer wrote:...To extract some kind of revision number which humans understand better we count the number of newlines of all listed sha1 values. So, to get this information you have to:

Code: Select all

git rev-list <sha1> | wc -l
...
Ahh, I knew about the sh1 values. Counting the newlines ... That is why I couldn'd find anything in my git book. Thanks Werner :)
User avatar
bernd
Posts: 10824
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: How to find a Revisionnr. of a Commit

Postby bernd » Mon Oct 19, 2015 10:59 am

see viewtopic.php?f=18&t=12883&p=103207#p103203 if one would like to have a commitID from a revision nr.
User avatar
DeepSOIC
Posts: 7810
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

Re: How to find a Revisionnr. of a Commit

Postby DeepSOIC » Mon Oct 19, 2015 11:10 am

Hmm. Some old thread. Anyway, here's how I usually get a revision number from commit:
github revision number.png
github revision number.png (87.13 KiB) Viewed 1759 times
User avatar
bernd
Posts: 10824
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: How to find a Revisionnr. of a Commit

Postby bernd » Mon Oct 19, 2015 11:39 am

Thanks przemo, haven't missed that opening the blob on github will show the revision id :D

Code: Select all

https://github.com/FreeCAD/FreeCAD/tree/Put_in_the_commitID
https://github.com/FreeCAD/FreeCAD/tree/bb05d1 shows revisionID 5560
User avatar
PrzemoF
Posts: 3049
Joined: Fri Jul 25, 2014 4:52 pm
Contact:

Re: How to find a Revisionnr. of a Commit

Postby PrzemoF » Mon Oct 19, 2015 1:36 pm

It wasn't me, but I can take the credit ;)
Mine solution below:

Code: Select all

[przemo@localhost freecad]$ git rev-list --count f654c632ba9366ba2527284424469d520e05e9e2 
2655
openBrain
Posts: 4647
Joined: Fri Nov 09, 2018 5:38 pm

Re: How to find a Revisionnr. of a Commit

Postby openBrain » Fri Dec 27, 2019 7:06 pm

Necro-bumping this thread in case ones could be interested in getting a commit number without having to use git (and mainly having to git-clone FC).
I issued a very simple way to get it at HEAD or at a specific SHA. ;)
For Windows users, cURL & sed can be downloaded from GoW.

Hope that helps. :)
vocx
Posts: 5206
Joined: Thu Oct 18, 2018 9:18 pm

Re: How to find a Revisionnr. of a Commit

Postby vocx » Fri Dec 27, 2019 7:31 pm

openBrain wrote:
Fri Dec 27, 2019 7:06 pm
I issued a very simple way to get it at HEAD or at a specific SHA.
It's two lines. You know you can just post it in this thread inside code tags...

Code: Select all

curl -I -k "https://api.github.com/repos/:owner/:repo/commits?per_page=1" | sed -n '/^Link:/ s/.*"next".*page=\([0-9]*\).*"last".*/\1/p'

### And that's all !
# I saw many fighting with finding first commit SHA or similar fancy thing.
# Here we just rely on the GH API, asking commits at 1 per page and parsing the last page number in the header of the reply (whose body only holds the last commit !)
# So this is robust and bandwidth efficient. :)

# If one want the commit count of a specific SHA, just use :
curl -I -k "https://api.github.com/repos/:owner/:repo/commits?per_page=1&sha=:sha" | sed -n '/^Link:/ s/.*"next".*page=\([0-9]*\).*"last".*/\1/p'
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.