如何 git-pull 除了一个文件夹之外的所有文件夹

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2416815/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 07:59:45  来源:igfitidea点击:

How to git-pull all but one folder

git

提问by atp

Is there any way to git pullall folders in the repository but one? I don't want to create a .gitignore file because other people may want the folder -- it's just too large for me to use right now.

除了一个之外,有没有办法访问git pull存储库中的所有文件夹?我不想创建一个 .gitignore 文件,因为其他人可能想要这个文件夹——它太大了,我现在无法使用。

Thanks!

谢谢!

采纳答案by VonC

I don't think you can do partial pulling, but you can try and see what happen if you pull in a working tree which is not completely checked out.

我不认为你可以做部分拉动,但是你可以尝试看看如果你拉入一个没有完全检出的工作树会发生什么。

Since Git1.7, you can do a sparse checkout, as illustrated here, meaning your working tree would explicitly exclude that specific folder when populate its content.

Git1.7 开始,您可以执行稀疏结帐,如下所示,这意味着您的工作树将在填充其内容时明确排除该特定文件夹。

Now if that directory is that big, it may be better to isolate it in an autonomous Git repository, allowing other users to refer to it as a submodule.

现在,如果该目录那么大,最好将其隔离在一个自治 Git 存储库中,允许其他用户将其称为submodule

回答by cforbish

If you want to get just and you could:

如果你想得到公正,你可以:

mkdir <repo>
cd <repo>
git init
git remote add -f origin <url>
git config core.sparsecheckout true
echo <dir1>/ >> .git/info/sparse-checkout
echo <dir2>/ >> .git/info/sparse-checkout
echo <dir3>/ >> .git/info/sparse-checkout
git pull origin master

I found a good reference here.

我在这里找到了一个很好的参考。