3

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.

Community
  • 1
  • 1
  • 1
    "This will give me only the files that were changed in revision 5317 and nothing else." - Are you sure this does not give you the files that were present in revision 5316 and unchanged in revision 5317? –  Nov 25 '13 at 16:26

4 Answers4

3

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

jthill
  • 55,082
  • 5
  • 77
  • 137
1

See man git-archive.

Also see this related question.

After that, you can do what you want with, for example:

git archive --remote=<repo> --output=repo-master.zip master
Community
  • 1
  • 1
elmart
  • 2,324
  • 15
  • 17
  • -1 because git archive doesn't work on a remote repo, it requires a clone first. –  Nov 25 '13 at 16:24
  • In the man page for git-archive, I can see the option --remote, with the following explanation: --remote= Instead of making a tar archive from the local repository, retrieve a tar archive from a remote repository. I'm using 1.8.4.3. To be fair, I didn't know that when I first answered, just checked the man page when I saw your comment. Maybe something added recently? – elmart Nov 25 '13 at 16:32
  • See [this](http://stackoverflow.com/questions/13750182/git-how-to-archive-from-remote-repository-directly), too. – elmart Nov 25 '13 at 16:38
  • problem is, this will get all files, not all changed files. – jthill Nov 25 '13 at 17:05
  • @jthill The way I understand the question, he wants all the files of a single revision. He says: *"Is it possible to export only the files from a single revision from a remote Git repository?"*. Subsequent *"[...] only the files that were changed in revision 5317"* can be confusing and lead to your interpretation, but I still think the author's original intent was just to get a particular revision, with all its files. – elmart Nov 25 '13 at 17:13
  • I see it now, what OP says he wants is just the changed files in a revision, but from a remote repo. I got the "only the changed files", you got the "remote repo" ... – jthill Nov 25 '13 at 17:17
  • @eleom Huh, interesting. If you edit your answer to include more details, I will undo my downvote. (I cannot do that now, SO won't let me unless you edit your answer.) –  Nov 25 '13 at 17:17
0

You can use this tool https://github.com/hegoku/git-export, install it and when you want to export modified files between two commits to a folder :

$ git-export -o /home/path_of_folder commit_1 commit_2

or if you just want to export modified files from specific commit to a folder:

$ git-export -o /home/path_fo_folder commit_1
Jack
  • 227
  • 3
  • 8
0

Use the --work-tree

This forces you to also use --git-dir to point to your .git directory. --git-dir=.git assumes that your are in your git folder. You can of course invoke this command from anywhere else, by adjusting this folder.

The following will checkout files to any directory you choose. This does not include any local (uncommitted) changes in the existing worktree. It does include changes in the index (put there with git add)

git  --git-dir=.git  --work-tree=/folder/into/which/to/export/  restore  .

Use --source=HEAD to ignore the index.

git  --git-dir=.git  --work-tree=/folder/into/which/to/export/  restore  --source=HEAD  .

Or you can use --source to specify any commit you want (branch, tag, hash).

git  --git-dir=.git  --work-tree=/folder/into/which/to/export/  restore  --source=my-tag  .

And you can even limit to some path inside your git repo

git  --git-dir=.git  --work-tree=/folder/into/which/to/export/  restore  --source=HEAD:path/in/your/repo  .

If you want part of the folder structure (for the sub-path) to be created in the dest folder

git  --git-dir=.git  --work-tree=/folder/into/which/to/export/  restore  --source=HEAD:path/in/  your/repo

Still only exports path/in/your/repo. But creates the directory /folder/into/which/to/export/your/repo.

Martin
  • 521
  • 5
  • 8