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

后端 未结 14 1651
醉梦人生
醉梦人生 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:20

    Updated answer 2020:

    There is now a command git sparse-checkout, that I present in detail with Git 2.25 (Q1 2020)

    nicono's answer illustrates its usage:

    git sparse-checkout init --cone # to fetch only root files
    git sparse-checkout add apps/my_app
    git sparse-checkout add libs/my_lib
    

    It has evolved with Git 2.27 and knows how to "reapply" a sparse checkout, as in here.
    Note that with Git 2.28, git status will mention that you are in a sparse-checked-out repository

    Original answer: 2016

    git 2.9 (June 2016) will generalize the --no-checkout option to git worktree add (the command which allows to works with multiple working trees for one repo)

    See commit ef2a0ac (29 Mar 2016) by Ray Zhang (OneRaynyDay).
    Helped-by: Eric Sunshine (sunshineco), and Junio C Hamano (gitster).
    (Merged by Junio C Hamano -- gitster -- in commit 0d8683c, 13 Apr 2016)

    The git worktree man page now includes:

    --[no-]checkout:
    

    By default, add checks out , however, --no-checkout can be used to suppress checkout in order to make customizations, such as configuring sparse-checkout.

提交回复
热议问题