wrfblog

Bill Fraser


wrf


Archives
2010 June
Valve
Win
2010 May
2010 February
2010 January
2009 October
2009 September
2009 April
2009 February
2009 January
2008 July
2008 May
2008 April
2008 March


Welcome back.
» forget me


Subscribe:
email:


Login:
password:
Sequential Revision Numbers in Git
Sun April 19th, 2009 at 8:11 AM PDT
I've been using Git for a while now on some of my projects, and find it utterly fantastic. It's faster than any SCM I've ever seen, and makes branches a snap. BAM!

But one thing has always annoyed me about it (well, other than being forced to lug the whole repo around when lots of times that isn't necessary):

Revision numbers are a nasty 40-byte hex string.

What good is that? I'm sure it's ultra-useful to the computer, but it tells me absolutely nothing about the given commit. I like Subversion's method, where commits start from 1 and go upward sequentially.

Well, today I figured out how to convert Git's 40-byte hashes into useful revision numbers. I actually figured this out for the benefit of the integrated SCM viewer and issue tracker software I've been working on, but have come to use it a lot outside of there.

Here's a handy shell script to convert Git SHA1 object names into sequential commit numbers:

git rev-list --reverse HEAD | grep -n $rev | cut -d: -f1

where $rev is the Git commit hash. Of course, you must be in your Git working directory for the command to work.

In my extremely informal experiments, the number printed by that command seems to be consistent across multiple distributed copies of the same repository, but merges may affect it. I don't know. But if you have a central repository, the number will never change for a given commit, and that's all that's really important.

Hope this helps someone!

_WRF

Edit:
Here's a nice addition to your .bashrc:

function git-rev-number()
{
if [[ $1 == "" ]]; then
echo "usage: git-rev-number "
return 1
fi
number=`git rev-list --reverse HEAD | grep -n $1 | cut -d: -f1`
if [[ $number == "" ]]; then
echo "commit not found"
return 1
else
echo $number
fi
return 0
}
» (1 comment) (make a comment)


Last 1 comments:

dru Thu September 17th, 2009 at 5:15 AM PDT No.443 (reply)
Nice idea, thank you :)

Name: (optional; defaults to "Anonymous")
Tripcode: (optional) What's a tripcode?
Link: (optional)
Image Verification: =
Message:
—»   
notice: — Allowed HTML tags: <b> <i> <u> <p> <br> <a href="" name=""> <ol> <ul> <li> <em> <strong> <strike> <font color="" size=""> <tt> <blockquote> <sub> <sup>
— You do not need to use <br> tags - hitting the enter key will suffice.
— Text in the form of "@[number]:" will be made into a link to the comment with that number (must be in the current post).
— You cannot not edit or delete your comment once it has been posted, so please thoroughly review it before posting.
— Posting constitutes acceptance of these terms.
Thanks!
Shoutbox
Anonymous:
lonely shoutbox :(
Mon April 7th, 2008 at 5:09 PM PDT
Anonymous:
hello
Mon April 7th, 2008 at 5:12 PM PDT
Anonymous:
o hai
Mon April 28th, 2008 at 12:31 PM PDT
CHIZUBAGA:
I CAN HAZ CHIZUBAGA!!!!!!!
Wed January 20th, 2010 at 12:58 PM PST
Not Jeremy:
o hai remember when i threw hot sauz in yer eye. lulz
Thu January 28th, 2010 at 11:28 AM PST
JEREMY:
MOAR NAPKINS DURR HURR
Thu February 11th, 2010 at 9:33 AM PST
Shoutbox:
I wuz on a DAtZ.. haffing chizubaga!! Om nom nom nom!!
Wed May 26th, 2010 at 1:04 PM PDT
Totally not anyone you know:
Problem?
Thu June 3rd, 2010 at 2:09 PM PDT
Random Randomstein:
Shitpickle.
Fri June 11th, 2010 at 6:04 PM PDT
Anti-spam field (don't enter anything! This field shouldn't really display at all - something is wrong...):
Name:
Link:
Text:
Anti-spam field (don't enter anything!):



22 database queries. Page generated in 111 milliseconds.
Powered by: CodewiseBlog Mainline v2.1.0.17-DEV
CodewiseBlog © 2004-2010 William R. Fraser / Codewise.org.
All textual content is the property of its author, subject to terms.
CodewiseBlog is free software under the GNU General Public License
CWB