git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* current repository hash
@ 2008-06-16 11:51 Alf Clement
  2008-06-16 12:11 ` David Tweed
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Alf Clement @ 2008-06-16 11:51 UTC (permalink / raw)
  To: git

Hi all,

I want to compile the current repository hash id into my program, to
be able to checkout later this
id an see the exact files for the compile. It should flag if there are
currently modified files in the
directory tree.

What would be the best command to get a unique identifier?
Do I need the 40 digit hash id?
How can I make sure that a shorter hash id will be unique?

Thanks,
Alf

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: current repository hash
  2008-06-16 11:51 current repository hash Alf Clement
@ 2008-06-16 12:11 ` David Tweed
  2008-06-16 12:15 ` Santi Béjar
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: David Tweed @ 2008-06-16 12:11 UTC (permalink / raw)
  To: Alf Clement; +Cc: git

On Mon, Jun 16, 2008 at 12:51 PM, Alf Clement <alf.clement@gmail.com> wrote:
> What would be the best command to get a unique identifier?

Note that git itself does this via the GIT-VERSION-GEN script so you
could look at that for ideas.

> How can I make sure that a shorter hash id will be unique?

Theoretically isn't that going to be tricky, as you don't just want
something that's unique at the time you compile the program but which
won't potentially be rendered non-unique by later commits (after
you've released your binary)? If you just want to be reasonably sure
you can truncate the hash to the length you'd like, eg "addcc13a" for
8 characters and run

git rev-parse addcc13a

and see if it says

addcc13a
fatal: ambiguous argument 'addcc13a': unknown revision or path not in
the working tree.
Use '--' to separate paths from revisions

-- 
cheers, dave tweed__________________________
david.tweed@gmail.com
Rm 124, School of Systems Engineering, University of Reading.
"while having code so boring anyone can maintain it, use Python." --
attempted insult seen on slashdot

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: current repository hash
  2008-06-16 11:51 current repository hash Alf Clement
  2008-06-16 12:11 ` David Tweed
@ 2008-06-16 12:15 ` Santi Béjar
  2008-06-16 18:30   ` Alf Clement
  2008-06-16 15:04 ` Jeff King
  2008-06-17  9:51 ` Johannes Schindelin
  3 siblings, 1 reply; 9+ messages in thread
From: Santi Béjar @ 2008-06-16 12:15 UTC (permalink / raw)
  To: Alf Clement; +Cc: git

On Mon, Jun 16, 2008 at 13:51, Alf Clement <alf.clement@gmail.com> wrote:
> Hi all,
>
> I want to compile the current repository hash id into my program, to
> be able to checkout later this
> id an see the exact files for the compile. It should flag if there are
> currently modified files in the
> directory tree.

You can look at how git does it:

http://git.kernel.org/?p=git/git.git;a=blob;f=GIT-VERSION-GEN;hb=HEAD

>
> What would be the best command to get a unique identifier?

"git rev-parse HEAD" for a unique identifier,
but "git describe" is more convenient/useful.

> Do I need the 40 digit hash id?

Normally 7 or 8 are sufficient.

> How can I make sure that a shorter hash id will be unique?

You can't. Even the 40 digit hash is "only" cryptographically unique.
But within a project 7 or 8 digits are unique enough for practical
use.

Santi

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: current repository hash
  2008-06-16 11:51 current repository hash Alf Clement
  2008-06-16 12:11 ` David Tweed
  2008-06-16 12:15 ` Santi Béjar
@ 2008-06-16 15:04 ` Jeff King
  2008-06-17  9:51 ` Johannes Schindelin
  3 siblings, 0 replies; 9+ messages in thread
From: Jeff King @ 2008-06-16 15:04 UTC (permalink / raw)
  To: Alf Clement; +Cc: git

On Mon, Jun 16, 2008 at 01:51:52PM +0200, Alf Clement wrote:

> What would be the best command to get a unique identifier?

If you just want the commit sha1, then "git rev-list -1 HEAD" will give
it to you. But take a look at git-describe, which is designed to give a
nice human-readable name based on your tags.

> Do I need the 40 digit hash id?

No, but you increase your chances of a collision in the future. In
practice, 8 or 9 characters tends to give unique commits.

> How can I make sure that a shorter hash id will be unique?

git-describe will find the shortest unique hash. But bear in mind that
it may not be unique forever.

-Peff

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: current repository hash
  2008-06-16 12:15 ` Santi Béjar
@ 2008-06-16 18:30   ` Alf Clement
  2008-06-16 18:45     ` Jeff King
  0 siblings, 1 reply; 9+ messages in thread
From: Alf Clement @ 2008-06-16 18:30 UTC (permalink / raw)
  To: git

Hi all,

thanks for the tips.

When I run describe I get an error:
$ git describe --debug HEAD
fatal: cannot describe '792815de6e3c2403f1e2ed5f2264ca88a0ae7000'

Any hints why? I have a tag v1.3 attached to HEAD and all commited.

CU,
Alf

On Mon, Jun 16, 2008 at 2:15 PM, Santi Béjar <sbejar@gmail.com> wrote:
> On Mon, Jun 16, 2008 at 13:51, Alf Clement <alf.clement@gmail.com> wrote:
>> Hi all,
>>
>> I want to compile the current repository hash id into my program, to
>> be able to checkout later this
>> id an see the exact files for the compile. It should flag if there are
>> currently modified files in the
>> directory tree.
>
> You can look at how git does it:
>
> http://git.kernel.org/?p=git/git.git;a=blob;f=GIT-VERSION-GEN;hb=HEAD
>
>>
>> What would be the best command to get a unique identifier?
>
> "git rev-parse HEAD" for a unique identifier,
> but "git describe" is more convenient/useful.
>
>> Do I need the 40 digit hash id?
>
> Normally 7 or 8 are sufficient.
>
>> How can I make sure that a shorter hash id will be unique?
>
> You can't. Even the 40 digit hash is "only" cryptographically unique.
> But within a project 7 or 8 digits are unique enough for practical
> use.
>
> Santi
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: current repository hash
  2008-06-16 18:30   ` Alf Clement
@ 2008-06-16 18:45     ` Jeff King
  2008-06-17  6:48       ` Alf Clement
  0 siblings, 1 reply; 9+ messages in thread
From: Jeff King @ 2008-06-16 18:45 UTC (permalink / raw)
  To: Alf Clement; +Cc: git

On Mon, Jun 16, 2008 at 08:30:16PM +0200, Alf Clement wrote:

> When I run describe I get an error:
> $ git describe --debug HEAD
> fatal: cannot describe '792815de6e3c2403f1e2ed5f2264ca88a0ae7000'
> 
> Any hints why? I have a tag v1.3 attached to HEAD and all commited.

By default, git-describe uses only annotated tags. Try "git describe
--tags HEAD".

-Peff

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: current repository hash
  2008-06-16 18:45     ` Jeff King
@ 2008-06-17  6:48       ` Alf Clement
  2008-06-17  7:07         ` Johan Herland
  0 siblings, 1 reply; 9+ messages in thread
From: Alf Clement @ 2008-06-17  6:48 UTC (permalink / raw)
  To: git

[-- Attachment #1: Type: text/plain, Size: 280 bytes --]

Hi all,

when I run
   $ git describe --tags HEAD
on my branch "fire1", I get:
    v1.5-13-g27f64b3

I wonder why it's -13. The last action I did was to merge the master branch,
which has the v1.5 tag. So it should be much less than 13?
A snapshot from gitk is attached.

CU,
Alf

[-- Attachment #2: git.jpg --]
[-- Type: image/jpeg, Size: 46065 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: current repository hash
  2008-06-17  6:48       ` Alf Clement
@ 2008-06-17  7:07         ` Johan Herland
  0 siblings, 0 replies; 9+ messages in thread
From: Johan Herland @ 2008-06-17  7:07 UTC (permalink / raw)
  To: git; +Cc: Alf Clement

On Tuesday 17 June 2008, Alf Clement wrote:
> Hi all,
>
> when I run
>    $ git describe --tags HEAD
> on my branch "fire1", I get:
>     v1.5-13-g27f64b3
>
> I wonder why it's -13. The last action I did was to merge the master
> branch, which has the v1.5 tag. So it should be much less than 13?
> A snapshot from gitk is attached.
>
> CU,
> Alf

AFAICS from your graph there are exactly 13 commits that are part of fire1, 
but not part of v.1.5 (from the bottom of the graph):
- "fire 1       modified: main.c"
- The 8 commits on a parallel branch leading towards origin/fire1
- The origin/fire1 merge
- The 4th last commit: "Merge branch 'master' into fire1"
- The 3rd last commit: "modified: main.c"
- The very last commit: fire1


...Johan

-- 
Johan Herland, <johan@herland.net>
www.herland.net

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: current repository hash
  2008-06-16 11:51 current repository hash Alf Clement
                   ` (2 preceding siblings ...)
  2008-06-16 15:04 ` Jeff King
@ 2008-06-17  9:51 ` Johannes Schindelin
  3 siblings, 0 replies; 9+ messages in thread
From: Johannes Schindelin @ 2008-06-17  9:51 UTC (permalink / raw)
  To: Alf Clement; +Cc: git

Hi,

On Mon, 16 Jun 2008, Alf Clement wrote:

> I want to compile the current repository hash id into my program, to be 
> able to checkout later this id an see the exact files for the compile.

If this program is meant for source-distribution, you might be interested 
in the "export-subst" attribute.  See Documentation/gitattributes.txt for 
details.

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2008-06-17  9:54 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-06-16 11:51 current repository hash Alf Clement
2008-06-16 12:11 ` David Tweed
2008-06-16 12:15 ` Santi Béjar
2008-06-16 18:30   ` Alf Clement
2008-06-16 18:45     ` Jeff King
2008-06-17  6:48       ` Alf Clement
2008-06-17  7:07         ` Johan Herland
2008-06-16 15:04 ` Jeff King
2008-06-17  9:51 ` Johannes Schindelin

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).