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.
Community
  • 1
  • 1
joelnet
  • 13,621
  • 5
  • 35
  • 49
  • 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 '12 at 07:32
  • 1
    detached HEAD just means that HEAD referes to a specific commit instead of a named branch. – Mattias Wadman Sep 12 '12 at 07:36
  • 1
    A commit is not a set of files; it's a set of changes to files. – Nicolas C Sep 12 '12 at 08: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](http://git-scm.com/book/en/Git-Internals-Git-Objects) for the details. – me_and Sep 12 '12 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 '12 at 13:57
  • Sorry for not being more clear. I have updated the question to add some clarification. – joelnet Sep 12 '12 at 19:10
  • @joelnet: Right. Thanks for reminding me about this. – Nicolas C Sep 20 '12 at 13:35

2 Answers2

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
Christopher
  • 42,720
  • 11
  • 81
  • 99
  • 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 '12 at 02: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

Debloper
  • 158
  • 1
  • 8