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.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

How to find a Revisionnr. of a Commit

Post by bernd »

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
Founder
Posts: 20202
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: How to find a Revisionnr. of a Commit

Post by wmayer »

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
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: How to find a Revisionnr. of a Commit

Post by bernd »

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
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: How to find a Revisionnr. of a Commit

Post by bernd »

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
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: How to find a Revisionnr. of a Commit

Post by DeepSOIC »

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 2793 times
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: How to find a Revisionnr. of a Commit

Post by bernd »

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
Veteran
Posts: 3515
Joined: Fri Jul 25, 2014 4:52 pm
Contact:

Re: How to find a Revisionnr. of a Commit

Post by PrzemoF »

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
Veteran
Posts: 9031
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: How to find a Revisionnr. of a Commit

Post by openBrain »

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
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: How to find a Revisionnr. of a Commit

Post by vocx »

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.
Post Reply