« Memory upgrade to 3Gpptp client howto on linux on console »

Sparse checkout example in git 1.7.0

2010. Feb. 14.

Permalink 01:00:23 am, by vmiklos, 137 words   English (US)
Categories: hacking

Sparse checkout example in git 1.7.0

Sparse checkout is now part of git-1.7.0. See here on what it is in general. Basically something what svn already knew for years and git did not. And of course git now does it better, since this way it’s possible to checkout multiple sub-directories, not just a single one, what svn allows.

Here is a short example:

$ git clone ~/git/git
$ cd git
$ ls|wc -l
361
$ git config core.sparsecheckout true
$ echo ppc/ > .git/info/sparse-checkout
$ echo perl/ >> .git/info/sparse-checkout
$ git read-tree -m -u HEAD
$ ls
perl/  ppc/

Enjoy! :)

Update: see the comments, as it has been pointed out the “And of course git now does it better, since this way it’s possible to checkout multiple sub-directories, not just a single one, what svn allows.” sentence is incorrect; but of course having a similar feature in a distributed VCS is still an improvement. ;)

14 comments

Comment from: viktor [Visitor]
miklós, szerintem nem ártana lecsekkolnod:

http://forums.frugalware.org/

sql error... pár napja ilyen. még egy ok, amiért nem szerencsés csak mailing listen keresztül csekkolni a fórumot :P
02/20/10 @ 02:28
Comment from: David R [Visitor] · http://blog.davr.org
Is it possible to just get the contents of a subdirectory, like how you can in SVN? Say I just wanted the contents of the 'perl/' dir, without an actual dir named 'perl' ?
02/25/10 @ 19:32
Comment from: vmiklos [Member]
I think that's only possible when you use submodules, see man git-submodule. But if you want to be sure, ask on the git list. :)
02/26/10 @ 01:35
Comment from: Eli Barzilay [Visitor] · http://barzilay.org/
FWIW, svn had sparse checkouts for *ages*.
With multiple directories.
04/30/10 @ 14:57
Comment from: vmiklos [Member]
Care to link some documentation how it is possible to do so?

I mean in case I have 3 subdirs in a repo and I want to check out only 2 of them. Manually checking out 2 of them is a no-go because then svn up won't update both.

Thanks.
04/30/10 @ 15:49
Comment from: Eli Barzilay [Visitor] · http://barzilay.org/
vmiklos: something like the following would get you two directories. (Note that I'm not saying whether one is better than the other, but saying that svn doesn't support that is just wrong.)
svn checkout $url --depth empty
svn update --set-depth infinity dir1
svn update --set-depth infinity dir2
04/30/10 @ 16:04
Comment from: Eli Barzilay [Visitor] · http://barzilay.org/
(Ugh, the last two updates should be done in the checkout empty directory, of course.)
04/30/10 @ 16:05
Comment from: vmiklos [Member]
Eli,

Thanks for the correction, I corrected the post. (See the update at the end of the post.)
04/30/10 @ 16:10
Comment from: Eli Barzilay [Visitor] · http://barzilay.org/
vmiklos: Thanks :)
(FWIW, I'm not trolling for svn... I was looking for information on git...)
04/30/10 @ 16:55
Comment from: Benjamin "balupton" Lupton [Visitor] Email · http://www.balupton.com
Sweet, but how do you turn it off once you've applied it.

Doing
$ echo "" > .git/info/sparse-checkout

as well as
$ git config core.sparsecheckout false

followed by
$ git read-tree -m -u HEAD
$ git pull

does not work... as I would have expected?
07/07/10 @ 13:41
Comment from: neokrates [Visitor] · http://www.thinkplexx.com
In your example i must first clone and then use "sparse checkout". Facing a large repository and read-only mode, i want "only" part of the repository, never all.
07/08/10 @ 15:34
Comment from: vmiklos [Member]
@Benjamin The best is to ask on the mailing list, right now I don't have time to dig the answer up for you, sorry.

@neokrates: You have various options, probably you just want git clone -n, that won't do a checkout, and then once you set up sparse checkout, you can do one.
07/08/10 @ 15:43
Comment from: vmiklos [Member]
@Benjamin I changed my mind, here is what you need:

echo '*' > .git/info/sparse-checkout
git read-tree -m -u HEAD

Then you can do:
rm .git/info/sparse-checkout
git config core.sparsecheckout false

(See man git-read-tree.)
07/08/10 @ 15:50
Comment from: neokrates [Visitor] · http://www.thinkplexx.com
@vmiklos Thank you for that great idea. Will try it on our build chain.
07/13/10 @ 01:28

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)
This is a captcha-picture. It is used to prevent mass-access by robots.
Please enter the characters from the image above. (case insensitive)
July 2010
Mon Tue Wed Thu Fri Sat Sun
 << <   > >>
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  

Search

Stats

Összesen 1,455 bejegyzés és 307 megjegyzés.

Most views

  • Sparse checkout example in git 1.7.0 (1,423)
  • winning london (987)
  • pacman -Sy: rsync-like optimization (888)
  • pacman-g2 -Qt bug (876)
  • gmane export (853)
  • More...
powered by b2evolution