Skip to content

How to fetch then checkout to a specific commit? #918

Answered by Byron
Evian-Zhang asked this question in Q&A
Discussion options

You must be logged in to vote

The above would indeed fetch a specific commit for which a pack is fetched. Checking it out doesn't have an API yet, and cloning doesn't support setting the commit - it always checks out the current HEAD.
In theory, you could try to use a refspec like <HASH>:HEAD in an attempt to write to HEAD directly, but I think it refuses this as it's illegal both for git and for gix, thus you can't use gix::prepare_clone(…) for this either.

Maybe the easiest is to adapt the exclusive-checkout code that is used by the clone machinery to checkout a particular tree into a directory. Note that this needs exclusive access, and it unconditionally writes into the given directory. Proper checkouts like git c…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Evian-Zhang
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants