1

I am currently exporting a git repository using:

git checkout-index -f --prefix=$TARGET_PATH/ $GIT_REPO_PATH/*

Actual behavior: The export happens on all files that are added to the index.

Desired behavior: Export all files that are not only added, but committed too.

I tried to use the --stage-option, but the stage is 0 for committed and uncommitted files (I have to say, I did not yet understand the stage numbers yet.

Any idea?

Luke Girvin
  • 13,221
  • 9
  • 64
  • 84
dexBerlin
  • 437
  • 3
  • 9
  • 22
  • Because it creates an archive (obviously ;) ), and I just need a plain export. – dexBerlin Jul 24 '12 at 07:48
  • 1
    So, what's wrong with `git archive HEAD | tar x -C"$TARGET_PATH"`? – knittl Jul 24 '12 at 07:52
  • Well, this compresses and then uncompresses the repository files. Practically it works, but it takes time and creates load. Isn't there a common way, how to do this? – dexBerlin Jul 24 '12 at 08:47
  • 2
    `tar` (without `-j` or `-z` options) does not compress. Copying takes time as well, I doubt there will be a noticeable overhead when using tar. – knittl Jul 24 '12 at 08:49
  • That's true. But using tar in between seems to be somehow senseless to me. But okay, if there is no direct way, I obviously have to cope with it. I will have to check if there is noticeable overhead. – dexBerlin Jul 24 '12 at 10:55
  • I'm adding this as an answer, since it seems to solve your problem. – knittl Jul 25 '12 at 09:35
  • see also/not-quite-duplicate: http://stackoverflow.com/q/2866358/151502 – Dogmatixed Nov 26 '14 at 18:16

3 Answers3

3

You cannot do that in one command, you have to load the files from a commits tree into an index first. Luckily, you don't have to use the normal index you work with:

$ export GIT_INDEX_FILE=.git/tmp-index
$ git read-tree HEAD && git checkout-index --prefix=/path/dir/ -f -a
$ rm "$GIT_INDEX_FILE"
fork0
  • 3,401
  • 23
  • 23
1

A simple, naïve solution to this problem is to use git archive. It will extract a tree from git history and write it to standard output. Piping trough tar allows you to write the files to a particular directory on disk.

# HEAD to use latest committed version
git archive HEAD | tar x -C"/path/to/dir"
knittl
  • 246,190
  • 53
  • 318
  • 364
1

I think git --work-tree=<path/to/wherever> checkout <HEAD/branch/hash> -- . does what you want. It will create a copy of (every file as it exists in the specified commit) in (the path specified by --work-tree).

Dogmatixed
  • 794
  • 1
  • 11
  • 33
  • This is the best answer, but you need to create the directory by yourself, otherwise you get this error: `fatal: This operation must be run in a work tree` – desertkun Oct 17 '17 at 12:07