On Mon, 7 Jan 2013 10:39:53 +0800
lei yang <yanglei.f...@gmail.com> wrote:

> I find my treeA want to have another treeB's dir, I don't want to
> clone the whole treeB, I don't know can we do it with git the get
> treeB's dir

You can't fetch just a directory from a remote tree as Git does not
explicitly track directories (some would even insist on that Git does
not even explicitly track files, but let's not touch this now), so
Git's remote protocol(s) have no idea about directories and files --
they only know about commits (and various ways to refer to them).

What you can do though is use the so-called "shallow cloning" to get a
minimum possible amount of history from the treeB and then extract the
relevant directory from it.
The way to go is to use the "--depth=1" command line option to
`git clone` which means telling it to fetch just the tip commit of
the single branch.  Note that the branch to fetch is defined by the
contents of the remote's HEAD reference; it's usually "master" but if
it isn't or if your treeB is not "master", then tell `git clone` which
branch you want to get using its "--branch=treeB" command-line option.
That is, use something like:

$ git clone --depth=1 --branch=treeB <remoteURL> <localDir>

Note that `git fetch` supports "shallow" mode of operation as well so
you can bring only the tip commit of the remote treeB into your
existing repository containing treeA -- this might have certain
operational advantages.


Reply via email to