Fork a file from a Git repository without cloning the repository

前端 未结 2 1324
你的背包
你的背包 2020-12-20 19:52

Is there a way to fork a file from a foreign Git repository without cloning the whole repository?

2条回答
  •  囚心锁ツ
    2020-12-20 20:39

    The closest you could get to doing this is by using sparse checkout, which means using Git 1.7+ and you still need to clone the repo (or use clone's --depth option to do a shallow clone). Borrowing largely from this answer, you could do the following:

    git clone --no-checkout  myrepo
    cd myrepo
    git config core.sparseCheckout true
    vim .git/info/sparse-checkout # Add files you want checked out
    git checkout 
    

    If you have Git version 1.7.7-rc0 or later, you can set configuration options with the clone command:

    git clone --config core.sparseCheckout=true --no-checkout  myrepo
    

    Also, see the following:

    • Partial clone with Git and Mercurial
    • How to retrieve a single file from specific revision in Git?
    • Sparse checkout in Git 1.7.0?
    • Is it possible to do a sparse checkout without checking out the whole repository first?

提交回复
热议问题