Is it possible to do a sparse checkout without checking out the whole repository first?

后端 未结 14 1764
醉梦人生
醉梦人生 2020-11-22 09:32

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 kin

14条回答
  •  臣服心动
    2020-11-22 10:22

    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 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

提交回复
热议问题