0

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:

  • There is an automated process that commits to this repository. (which is why i don't want to detach the HEAD)
  • I want to extract all files from the repository from a specific point. (i know the commit id)
  • I'd like to extract these files to an alternate location.
7
  • when you say extract - what do you mean? You want to get all files at that given commit, all files that are in that commit?
    – AD7six
    Sep 12, 2012 at 7:32
  • 1
    detached HEAD just means that HEAD referes to a specific commit instead of a named branch. Sep 12, 2012 at 7:36
  • 1
    A commit is not a set of files; it's a set of changes to files.
    – Nicolas C
    Sep 12, 2012 at 8:41
  • 1
    @Nicolas: No. That's one of the fundamental differences between Git and VCSs such as Subversion: a Git commit points to a set of files, not to a difference between sets of files. Take a read of the Git object model for the details.
    – me_and
    Sep 12, 2012 at 13:56
  • @joelnet It's not clear from your question what you're trying to achieve, and in particular, why having a detached HEAD is a problem for you.
    – me_and
    Sep 12, 2012 at 13:57

2 Answers 2

2

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
1
  • git archive is the closest to what I want to do. I will extract the files I want without changing the HEAD. for some reason I thought this would be easier.
    – joelnet
    Sep 13, 2012 at 2:12
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.