# Is there a way to fetch commits that are detached

2 messages from 2012-04-24 to 2012-04-24. Participants: Allan Caffee, Junio C Hamano.
Thread: https://gitlist.dev/t/30328

## Allan Caffee, 2012-04-24 21:49

Subject: Is there a way to fetch commits that are detached
Message-ID: <CA+jCPNcmcxQcSN_BNvigQa2uRiaw-c2PK5T-y1yacYNs6Ws4WA@mail.gmail.com>
URL: https://gitlist.dev/e/CA%2BjCPNcmcxQcSN_BNvigQa2uRiaw-c2PK5T-y1yacYNs6Ws4WA%40mail.gmail.com

```
First some context: I'm trying to use the pre-receive hook to run some tests
on a Hudson server before accepting the updates to a branch. At the moment I'm
trying to have the Hudson job clone the repository (using the "git" protocol)
and checkout the new ref as a detached head e.g.

$ git clone $GIT_REPOSITORY repository
$ cd repository
$ git checkout $GIT_COMMIT

But the checkout fails, apparently because the commit object hasn't been
pulled into the local repository. Only a pack file is present in the local
repository's objects directory which presumably doesn't have the commit.

Is there a way to explicitly fetch whatever objects are necessary to checkout
the commit?

Would I be better off using git-archive to tar up a copy of the source
instead, or some other means of copying the codebase over for testing?

Thanks,
Allan

```

## Junio C Hamano, 2012-04-24 22:15

Subject: Re: Is there a way to fetch commits that are detached
Message-ID: <xmqq62cog4iz.fsf@junio.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqq62cog4iz.fsf%40junio.mtv.corp.google.com
In-Reply-To: <CA+jCPNcmcxQcSN_BNvigQa2uRiaw-c2PK5T-y1yacYNs6Ws4WA@mail.gmail.com>

```
Allan Caffee <allan.caffee@gmail.com> writes:

> Is there a way to explicitly fetch whatever objects are necessary to checkout
> the commit?

One security principle built into git is that any object that is
unreachable from refs/* is not to be exposed to outside world.  If the
commit is not on any ref, you shouldn't be able to obtain it remotely.

So you need to know which branch (or it could be a tag) the commit you
want is on, fetch that branch or tag and then check the commit out.

```
