# Better way to find commit from tarball?

2 messages from 2010-09-06 to 2010-09-06. Participants: Todd A. Jacobs, Jonathan Nieder.
Thread: https://gitlist.dev/t/25010

## Todd A. Jacobs, 2010-09-06 19:55

Subject: Better way to find commit from tarball?
Message-ID: <AANLkTi=ZnZppPu8tT3-sUG6zZM8YnonPwMG_XZhO03up@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTi%3DZnZppPu8tT3-sUG6zZM8YnonPwMG_XZhO03up%40mail.gmail.com

```
Someone handed me a tarball that represented an unknown release from a
project. Here's what I came up with to identify the commit:

    cd $SOME_WORK_DIR
    find . -path ./.git -prune -o -print0 | xargs -0 rm
    tar xvfz $TARBALL
    for commit in {0..100}; do
        id="master~${commit}"
        if git diff --quiet --exit-code "$id"
        then
            echo "Matched on commit $id"
            break
        fi
    done

Someone please tell me there's an easier way to find a matching tree
when handed a tarball. This works, but seems cumbersome.

```

## Jonathan Nieder, 2010-09-06 20:05

Subject: Re: Better way to find commit from tarball?
Message-ID: <20100906200508.GA26371@burratino>
URL: https://gitlist.dev/e/20100906200508.GA26371%40burratino
In-Reply-To: <AANLkTi=ZnZppPu8tT3-sUG6zZM8YnonPwMG_XZhO03up@mail.gmail.com>

```
Todd A. Jacobs wrote:

>     cd $SOME_WORK_DIR
>     find . -path ./.git -prune -o -print0 | xargs -0 rm
>     tar xvfz $TARBALL
>     for commit in {0..100}; do
>         id="master~${commit}"
>         if git diff --quiet --exit-code "$id"
>         then
>             echo "Matched on commit $id"
>             break
>         fi
>     done
> 
> Someone please tell me there's an easier way to find a matching tree
> when handed a tarball. This works, but seems cumbersome.

If you are lucky and they used "git archive":

	gunzip <$TARBALL | git get-tar-commit-id

Otherwise: maybe something like this[1] will work.

	tar_id=$(
		git init tarball &&
		cd tarball &&
		perl /usr/share/doc/git/contrib/fast-import/import-tars.perl $TARBALL &&
		git rev-parse --verify HEAD:
	) &&
	rm -fr tarball &&
	git rev-list --full-history --format='%h %T' HEAD |
	grep " $tar_id\$"

[1] http://thread.gmane.org/gmane.comp.version-control.git/44750/focus=44849

```
