Greg Hewgill Greg Hewgill - 1 year ago 80
Git Question

Do a "git export" (like "svn export")?

I've been wondering whether there is a good "git export" solution that creates a copy of a tree without the

repository directory. There are at least three methods I know of:

  1. git clone
    followed by removing the
    repository directory.

  2. git checkout-index
    alludes to this functionality but starts with "Just read the desired tree into the index..." which I'm not entirely sure how to do.

  3. git-export
    is a third party script that essentially does a
    git clone
    into a temporary location followed by
    rsync --exclude='.git'
    into the final destination.

None of these solutions really strike me as being satisfactory. The closest one to
svn export
might be option 1, because both those require the target directory to be empty first. But option 2 seems even better, assuming I can figure out what it means to read a tree into the index.

Answer Source

Probably the simplest way to achieve this is with git archive. If you really need just the expanded tree you can do something like this.

git archive master | tar -x -C /somewhere/else

Most of the time that I need to 'export' something from git, I want a compressed archive in any case so I do something like this.

git archive master | bzip2 >source-tree.tar.bz2

ZIP archive:

git archive --format zip --output /full/path/to/ master 

git help archive for more details, it's quite flexible.

Note: If you are interested in exporting the index, the command is

git checkout-index -a -f --prefix=/destination/path/

(See Greg's answer for more details)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download