Is it possible to do a sparse checkout without che

2018-12-31 16:47发布

I'm working with a repository with a very large number of files that takes hours to checkout. I'm looking into the possibility of whether Git would work well with this kind of repository now that it supports sparse checkouts but every example that I can find does the following:

git clone <path>
git config core.sparsecheckout true
echo <dir> > .git/info/sparse-checkout
git read-tree -m -u HEAD

The problem with this sequence of commands is the original clone also does a checkout. If you add -n to the original clone command, then the read-tree command results in the following error:

error: Sparse checkout leaves no entry on working directory

How can do the sparse checkout without checking out all the files first?

标签: git
8条回答
牵手、夕阳
2楼-- · 2018-12-31 17:11

Yes, sparse-checkout download whole stuff to download a folder from git. None of the above methods work for me. To downlaod only a single sample from https://github.com/gearvrf/GearVRf-Demos here is what I did..

  1. For windows user download and install SlikSvn_x84, add this "C:\Program Files (x86)\SlikSvn\bin" to Path environment variable. mac user use alternative svn client.

  2. Use command line : svn export https://github.com/foobar/Test.git/trunk/foo

Notice the URL format:

The base URL is https://github.com/ /trunk appended at the end

Example : svn export https://github.com/gearvrf/GearVRf-Demos.git/trunk/gvr-renderableview

I hope this will help someone. ref: https://stackoverflow.com/a/18324458/5710872

查看更多
几人难应
3楼-- · 2018-12-31 17:15

Please note that this answer does download a complete copy of the data from a repository. The git remote add -f command will clone the whole repository. From the man page of git-remote:

With -f option, git fetch <name> is run immediately after the remote information is set up.


Try this:

mkdir myrepo
cd myrepo
git init
git config core.sparseCheckout true
git remote add -f origin git://...
echo "path/within_repo/to/desired_subdir/*" > .git/info/sparse-checkout
git checkout [branchname] # ex: master

Now you will find that you have a "pruned" checkout with only files from path/within_repo/to/desired_subdir present (and in that path).

Note that on windows command line you must not quote the path, i.e. you must change the 6th command with this one:

echo path/within_repo/to/desired_subdir/* > .git/info/sparse-checkout

if you don't you'll get the quotes in the sparse-checkout file, and it will not work

查看更多
登录 后发表回答