threads / discuss / 7635

sha1 of the repo excluding history ?

Subject: sha1 of the repo excluding history ?

## tl;dr

3 messages between Apr 12, 2007 and Apr 13, 2007.

replies: 2people: 3as markdown or json

Yakov Lerner· Apr 12, 2007, 23:26 UTC · lore
    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· Apr 12, 2007, 23:40 UTC · re: Yakov Lerner · lore

Re: sha1 of the repo excluding history ?

Yakov Lerner <iler.ml@gmail.com> wrote:
Show 9 quoted lines
>    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· Apr 13, 2007, 00:24 UTC · re: Yakov Lerner · lore

Re: sha1 of the repo excluding history ?

"Yakov Lerner" <iler.ml@gmail.com> writes:
Show 11 quoted lines
>    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.

← back to recent threads