I have a git project that I used for a recently published scientific paper. In the project I have subdirectories doc
(split into doc/paper
doc/talks
) results
src
and more.
Now I would like to release my source code (but not my presentation slides, etc.). What is the best way to give people access to just the src
subdirectory? I would release a zip file taking a snapshot of the current src directory, but I want people to get updates easily.
Thanks a lot. Oliver
Short version:
You need to use a separate repo per top-level folder you want to give access to. See submodules for more info on how to go about doing that.
"sparse" checkouts could work, but I believe this cannot be forced upon your users, who has to clone the entire repository to local anyway, then just get a partial working directory.
(You could also setup a separate repo that would be auto-updated and push changes to that, but you lose the opportunity to merge forks and fixes from your userbase, which is sort of the point, I guess.)
Longer version: Wo The "new" distributed version control systems (Git, Mercurial, Bazaar, etc) are not built around per-folder checkout in the same fashion as SVN and CVS. Having the branching tree separate from the directory tree simplifies handling branches and merges in the revision graph, as these are more numerous than for centralized VC:es. (SVN, IMO, handle branches & merges like a sledgehammer handles opening a can of spam, much of this is due to the fact that any directory in the hierarchy can be branched/merged).
The partial checkouts feature is easy to give in centralized scenarios where you don't branch/merge, and was therefore popular in the dawn of time. You don't get that anymore, and will probably learn to be thankful for not having it. :)
Having a few subrepos/submodules of the important stuff is therefore easier. Branching the top repo is slightly more complicated though, so you need to think about how you want to set things up to make things easy for you to work with. (Maybe releasing the presentation slides is not that bad? :)
There is no way to check out just a subfolder of a repository using git
.
You could make the subfolder its own repository, or distribute tarballs/zipfiles as you suggest.
As of git 1.7, there is support for "sparse checkouts" - see here - but that's only the working copy that's sparse; you'd still have to give the users the ability to clone your whole repository.
As stated in the Git Book under the submodules chapter, Git does not allow partial checkouts.
You may just keep as private your repository and move the development of src/ to a new, public one. Maybe on github, it has some community features -- e.g. bug tracking, follow -- that would simplify things for your followers.
来源:https://stackoverflow.com/questions/9380704/checkout-subfolder-in-git