Archives
2010 June 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:
Login:
|
| 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 }
|
|
»
(make a comment)
|
Comments:
Nice idea, thank you :)
[Page 1] [All One Page]
» (make a comment)
|
| 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
|
|