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

ID : 295

viewed : 30

Tags : gitexportgit-archivesvn-exportgit

Top 5 Answer for Do a "git export" (like "svn export")?

vote vote


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.

Be aware that even though the archive will not contain the .git directory, it will, however, contain other hidden git-specific files like .gitignore, .gitattributes, etc. If you don't want them in the archive, make sure you use the export-ignore attribute in a .gitattributes file and commit this before doing your archive. Read more...

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)

vote vote


I found out what option 2 means. From a repository, you can do:

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

The slash at the end of the path is important, otherwise it will result in the files being in /destination with a prefix of 'path'.

Since in a normal situation the index contains the contents of the repository, there is nothing special to do to "read the desired tree into the index". It's already there.

The -a flag is required to check out all files in the index (I'm not sure what it means to omit this flag in this situation, since it doesn't do what I want). The -f flag forces overwriting any existing files in the output, which this command doesn't normally do.

This appears to be the sort of "git export" I was looking for.

vote vote


git archive also works with remote repository.

git archive --format=tar \ --remote=ssh://remote_server/remote_repository master | tar -xf - 

To export particular path inside the repo add as many paths as you wish as last argument to git, e.g.:

git archive --format=tar \ --remote=ssh://remote_server/remote_repository master path1/ path2/ | tar -xv 
vote vote


enter image description here

A special case answer if the repository is hosted on GitHub.

Just use svn export.

As far as I know Github does not allow archive --remote. Although GitHub is svn compatible and they do have all git repos svn accessible so you could just use svn export like you normally would with a few adjustments to your GitHub url.

For example to export an entire repository, notice how trunk in the URL replaces master (or whatever the project's HEAD branch is set to):

svn export 

And you can export a single file or even a certain path or folder:

svn export 

Example with jQuery JavaScript Library

The HEAD branch or master branch will be available using trunk:

svn ls 

The non-HEAD branches will be accessible under /branches/:

svn ls 

All tags under /tags/ in the same fashion:

svn ls 
vote vote


From the Git Manual:

Using git-checkout-index to "export an entire tree"

The prefix ability basically makes it trivial to use git-checkout-index as an "export as tree" function. Just read the desired tree into the index, and do:

$ git checkout-index --prefix=git-export-dir/ -a

Top 3 video Explaining Do a "git export" (like "svn export")?