Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sparse checkout in Git 1.7.0?

With the new sparse checkout feature in Git 1.7.0, is it possible to just get the contents of a subdirectory like how you can in SVN? I found this example, but it preserves the full directory structure. Imagine that I just wanted the contents of the 'perl' directory, without an actual directory named 'perl'.

-- EDIT --

Example:

My git repository contains the following paths

repo/.git/ repo/perl/ repo/perl/script1.pl repo/perl/script2.pl repo/images/ repo/images/image1.jpg repo/images/image2.jpg repo/doc/ repo/doc/readme.txt repo/doc/help.txt 

What I want is to be able to produce from the above repository this layout:

repo/.git/ repo/script1.pl repo/script2.pl 

However with the current sparse checkout feature, it seems like it is only possible to get

repo/.git/ repo/perl/script1.pl repo/perl/script2.pl 

which is NOT what I want.

like image 801
davr Avatar asked Feb 25 '10 18:02

davr


People also ask

How do I enable sparse checkout?

Enable the necessary sparse-checkout config settings ( core. sparseCheckout , core. sparseCheckoutCone , and index. sparse ) if they are not already set to the desired values, populate the sparse-checkout file from the list of arguments following the set subcommand, and update the working directory to match.

How do I disable sparse checkout?

Disable the core. sparseCheckout config setting, and restore the working directory to include all files. Leaves the sparse-checkout file intact so a later git sparse-checkout init command may return the working directory to the same state.


2 Answers

You still need to clone the whole repository, which will have all the files. You could use the --depth flag to only retrieve a limited amount of history.

Once the repository is cloned, the read-tree trick limits your "view" of the repository to only those files or directories that are in the .git/info/sparse-checkout file.

I wrote a quick script to help manage the sparseness, since at the moment it is a bit unfriendly:

#!/bin/sh echo > .git/info/sparse-checkout for i in "$@" do     echo "$i" >> .git/info/sparse-checkout done git read-tree -m -u HEAD 

If you save this script as git-sparse.sh into the path reported by calling git --exec-path, then you can run git sparse foo/ bar/ to only "checkout" the foo and bar directories, or git sparse '*' to get everything back again.

like image 187
richq Avatar answered Sep 29 '22 11:09

richq


The short answer is no. Git sees all files as a single unit.

What I recommend is that you break down you repositories into logical chunks. A separate one for perl, images, and docs. If you also needed to maintain the uber repo style you can create a repo made up of Submodules.

like image 33
John K Avatar answered Sep 29 '22 11:09

John K