从Git存储库中分叉文件,而无需克隆存储库 [英] Fork a file from a Git repository without cloning the repository
本文介绍了从Git存储库中分叉文件,而无需克隆存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法在不克隆整个存储库的情况下从外部Git存储库派生文件?
Is there a way to fork a file from a foreign Git repository without cloning the whole repository?
推荐答案
最接近此效果的方法是使用 clone
的--depth
选项进行浅层克隆).主要从此答案中借用,您可以执行以下操作:
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 <URL to git repo> myrepo
cd myrepo
git config core.sparseCheckout true
vim .git/info/sparse-checkout # Add files you want checked out
git checkout <branch you want>
如果您的Git版本为1.7.7-rc0或更高版本,则可以使用clone
命令设置配置选项:
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 <URL to git repo> 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?
这篇关于从Git存储库中分叉文件,而无需克隆存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文