joelnet
joelnet

Reputation: 14241

How can I shallow clone all files from a repository at a specific commit?

I am trying to extract shallow clone all files from a repository at a specific commit. I would like to extract these files to an alternate location without affecting the HEAD of the existing repository.

This is the command I'm running to get those files...

git --git-dir="C:\temp\repository" --work-tree="C:\temp\files" checkout -f "e2f4b8cf188c87db6a11c6f421b06f701dd6b07b"

The above command works to extract the files I want, but my problem is this leaves my repository with a detached HEAD.

What is the best way to extract these files?

Possible duplicate: How to shallow clone a specific commit with depth 1?

edits for clarification:

Upvotes: 0

Views: 765

Answers (2)

Christopher
Christopher

Reputation: 44244

I'm having trouble telling quite what you want, so here are a few methods to get at a commit or the repository state at its commit time. Suppose the commit is 1234abcd

1) Two ways to view the repository state at 1234abcd:

git checkout 1234abcd ;# 'detached HEAD' state; just don't commit new work    
git reset --hard 1234abcd ;# fully reset to the commit, abandon uncommitted work

2) Zip up the repository state at 1234abcd

git archive -o myfile.zip 1234abcd ;# zip up into 'myfile.zip'

3) Create an email patch from 1234abcd

git format-patch -M 1 1233abcd

4) Output git patch format so you could reuse it (e.g. git apply will read the output of git diff, you can pipe the latter to the former)

git diff 1234abcd 1234abcd~1 | git apply ;# create and reapply the patch to the index
git diff 1234abcd 1234abcd~1 > outfile.txt ;# redirect it to an outfile

Upvotes: 2

Debloper
Debloper

Reputation: 158

Fetch the branch from the other repo (don't pull, i.e. don't merge the branches), then cherry-pick the commit from the other branch. That will take that particular change to the current branch & commit it with its full history.

More details on Git Cherry Pick: http://git-scm.com/docs/git-cherry-pick

Upvotes: 0

Related Questions