# current repository hash

9 messages from 2008-06-16 to 2008-06-17. Participants: Alf Clement, David Tweed, Santi Béjar, Jeff King, Johan Herland, Johannes Schindelin.
Thread: https://gitlist.dev/t/13978

## Alf Clement, 2008-06-16 11:51

Subject: current repository hash
Message-ID: <556d90580806160451g36daefb6o48b93b92589211bf@mail.gmail.com>
URL: https://gitlist.dev/e/556d90580806160451g36daefb6o48b93b92589211bf%40mail.gmail.com

```
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

```

## David Tweed, 2008-06-16 12:11

Subject: Re: current repository hash
Message-ID: <e1dab3980806160511s1a9a5192gbdf6539205ef1865@mail.gmail.com>
URL: https://gitlist.dev/e/e1dab3980806160511s1a9a5192gbdf6539205ef1865%40mail.gmail.com
In-Reply-To: <556d90580806160451g36daefb6o48b93b92589211bf@mail.gmail.com>

```
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

```

## Santi Béjar, 2008-06-16 12:15

Subject: Re: current repository hash
Message-ID: <8aa486160806160515p751b2af4j2b0db6db7a9ad482@mail.gmail.com>
URL: https://gitlist.dev/e/8aa486160806160515p751b2af4j2b0db6db7a9ad482%40mail.gmail.com
In-Reply-To: <556d90580806160451g36daefb6o48b93b92589211bf@mail.gmail.com>

```
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

```

## Jeff King, 2008-06-16 15:04

Subject: Re: current repository hash
Message-ID: <20080616150416.GA6164@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20080616150416.GA6164%40sigill.intra.peff.net
In-Reply-To: <556d90580806160451g36daefb6o48b93b92589211bf@mail.gmail.com>

```
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

```

## Alf Clement, 2008-06-16 18:30

Subject: Re: current repository hash
Message-ID: <556d90580806161130g62269318i46f00e5c7f79b7d9@mail.gmail.com>
URL: https://gitlist.dev/e/556d90580806161130g62269318i46f00e5c7f79b7d9%40mail.gmail.com
In-Reply-To: <8aa486160806160515p751b2af4j2b0db6db7a9ad482@mail.gmail.com>

```
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
>

```

## Jeff King, 2008-06-16 18:45

Subject: Re: current repository hash
Message-ID: <20080616184520.GA11992@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20080616184520.GA11992%40sigill.intra.peff.net
In-Reply-To: <556d90580806161130g62269318i46f00e5c7f79b7d9@mail.gmail.com>

```
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

```

## Alf Clement, 2008-06-17 06:48

Subject: Re: current repository hash
Message-ID: <556d90580806162348q6c6b90daoe48c3fa330f488ec@mail.gmail.com>
URL: https://gitlist.dev/e/556d90580806162348q6c6b90daoe48c3fa330f488ec%40mail.gmail.com
In-Reply-To: <20080616184520.GA11992@sigill.intra.peff.net>

```
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

```

## Johan Herland, 2008-06-17 07:07

Subject: Re: current repository hash
Message-ID: <200806170907.39665.johan@herland.net>
URL: https://gitlist.dev/e/200806170907.39665.johan%40herland.net
In-Reply-To: <556d90580806162348q6c6b90daoe48c3fa330f488ec@mail.gmail.com>

```
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

```

## Johannes Schindelin, 2008-06-17 09:51

Subject: Re: current repository hash
Message-ID: <alpine.DEB.1.00.0806171050440.6439@racer>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0806171050440.6439%40racer
In-Reply-To: <556d90580806160451g36daefb6o48b93b92589211bf@mail.gmail.com>

```
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

```
