Reputation:
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.
Upvotes: 3
Views: 1786
Reputation: 551
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
.
Upvotes: 0
Reputation: 247
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
Upvotes: 0
Reputation: 2374
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
Upvotes: 1
Reputation: 60487
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
Upvotes: 3