David Tay David Tay - 4 years ago 164
Git Question

Git export exactly like SVN export

Is it possible to export only the files from a single revision from a remote Git repository? In Subversion, we can easily do this:

svn export https://some.website.com/trunk/app/etc@5317 --username=user --password=pass --force -r 5317 ./build/trunk/app


This will give me only the files that were changed in revision 5317 and nothing else. Why is this not possible in Git?

Note: I've already read How to do a “git export” (like “svn export”), but all the answers refer to some variation of cloning an entire repository. I don't need an entire work tree. I just need a handful of files. My repository is 4.5 gigs and my FTP build system hosted on a VM charges for inbound and has limited disk space. Any help appreciated.

Answer Source

This will give me only the files that were changed in revision 5317 and nothing else. Why is this not possible in Git?

There's no pushbutton for it because git fetch or any of several other git ways are better, but dumping full contents of files changed in a commit is

git clone --no-checkout . ../scratch     # dirt cheap
( cd ../scratch
  git diff-tree --name-only -r commit^! | xargs git checkout commit -- 
  git ls-files | tar czTf - ../export.tgz
)
rm -rf ../scratch

The git way to do minimal fetches is to start from a shallow clone. It's possible to do this in an ex post facto way, and even to avoid having anything in the object db at all, but unless disk space is at some ridiculous premium the git way to do this from your remote site is

git clone --depth=1 -b mainbranch u://r/l 

and from then on, just

git pull

to keep up-to-date

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