# sha1 of the repo excluding history ?

3 messages from 2007-04-12 to 2007-04-13. Participants: Yakov Lerner, Shawn O. Pearce, Junio C Hamano.
Thread: https://gitlist.dev/t/7635

## Yakov Lerner, 2007-04-12 23:26

Subject: sha1 of the repo excluding history ?
Message-ID: <f36b08ee0704121626i6a27dcecp8b0b10e0f7db2ef7@mail.gmail.com>
URL: https://gitlist.dev/e/f36b08ee0704121626i6a27dcecp8b0b10e0f7db2ef7%40mail.gmail.com

```
    Can I obtain from git the sha1 of the total last state of the
repo excluding history ? This is a state that covers contents and
names of all files and dirs, and x perm of files;
but excludes history, timestamps, ownerhisp, and inode numbers.

That would be approximately like the slow method:
          'find | egrep -v '/\.git(/|$)' | sort | Xcpio -o | sha1sum -'
(imagining Xcpio that does not archive any ownership, timestamps,
and inode numbers). Can I obtain this result immediately from git ?

Yakov

```

## Shawn O. Pearce, 2007-04-12 23:40

Subject: Re: sha1 of the repo excluding history ?
Message-ID: <20070412234032.GE12979@spearce.org>
URL: https://gitlist.dev/e/20070412234032.GE12979%40spearce.org
In-Reply-To: <f36b08ee0704121626i6a27dcecp8b0b10e0f7db2ef7@mail.gmail.com>

```
Yakov Lerner <iler.ml@gmail.com> wrote:
>    Can I obtain from git the sha1 of the total last state of the
> repo excluding history ? This is a state that covers contents and
> names of all files and dirs, and x perm of files;
> but excludes history, timestamps, ownerhisp, and inode numbers.
> 
> That would be approximately like the slow method:
>          'find | egrep -v '/\.git(/|$)' | sort | Xcpio -o | sha1sum -'
> (imagining Xcpio that does not archive any ownership, timestamps,
> and inode numbers). Can I obtain this result immediately from git ?

	git rev-parse HEAD^{tree}

The trick here is ^{tree}; this operator takes a commit-ish (commit
or tag) and returns the SHA-1 of the tree that the commit-ish
points at.  That SHA-1 is the SHA-1 of the file contents, names,
and executable bits, but nothing else.  No history.

I use it sometimes after a rebase when I reorganize history:

	old=`git rev-parse HEAD^{tree}`
	.... do rebasing magick ...
	test $old = `git rev-parse HEAD^{tree}` && echo GOOD

If I don't get back GOOD then I know I somehow changed the files in
a way that isn't what I had before, and that wasn't what I wanted
if all I was doing was cleaning up commit messages.

-- 
Shawn.

```

## Junio C Hamano, 2007-04-13 00:24

Subject: Re: sha1 of the repo excluding history ?
Message-ID: <7v7ishi0k0.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7v7ishi0k0.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <f36b08ee0704121626i6a27dcecp8b0b10e0f7db2ef7@mail.gmail.com>

```
"Yakov Lerner" <iler.ml@gmail.com> writes:

>    Can I obtain from git the sha1 of the total last state of the
> repo excluding history ? This is a state that covers contents and
> names of all files and dirs, and x perm of files;
> but excludes history, timestamps, ownerhisp, and inode numbers.
>
> That would be approximately like the slow method:
>          'find | egrep -v '/\.git(/|$)' | sort | Xcpio -o | sha1sum -'
> (imagining Xcpio that does not archive any ownership, timestamps,
> and inode numbers). Can I obtain this result immediately from git ?
>
> Yakov

I think you are talking about tree object name.  git-cat-file
commit HEAD and look at "tree xxx" line.

You can use "git tar-tree $tree_object_name" to tar it up,
and "git ls-tree -r $tree_object_name" to list all the blob
object names with their perms.

```
