6

git检出部分文件夹或文件

 3 years ago
source link: https://www.wencst.com/archives/706
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

git检出部分文件夹或文件

作者: wencst 分类: linux,windows 发布时间: 2017-11-21 11:45 阅读: 2,734 次

一、问题概述

对于大型git仓库,执行git命令时,都会等待很长时间。于是能否只检出部分文件或文件夹呢?

二、可用方案

使用wget方法

wget http://github.com/abc.txt

此方法适用于公开的git地址和文件,如果涉及到输入密码,则只会下载一个html。

使用gitzip或DownGit工具,我没有使用过,后面如果用得话再补充。

使用git的稀疏检出功能(sparse checkout),个人觉得这个方案为官方提供,且简单有效,所以采用了这个方案。

1.首先确定git工具版本,需要在1.7.0以上。

git -version

2.建立文件夹,并初始化此文件夹为git文件夹

mkdir gittest

cd gittest

git init

3.设置git为稀疏检出,并设置检出文件夹和文件(可以同时输入多个文件夹或文件)

git config core.sparseCheckout true

echo /dir1/* >> .git/info/sparse-checkout

echo /README.md >> .git/info/sparse-checkout

git config –list(最后一行会显示是否打开稀疏检出功能)

4.查看并初始化远程仓库地址

git remote -v

git remote add origin http://github.com/wencst/xxx.git

5.执行检出

git pull origin master

6.如果后续需要增加或减少检出的文件夹,只需修改.git/info/sparse-checkout文件即可

echo /dir2/* >> .git/info/sparse-checkout

cat  .git/info/sparse-checkout

三、后续说明

.git/info/sparse-checkout 中使用和 .gitignore 相同的匹配模式,例如 非匹配 !/dir2/* 以及 /*.java 等。

如果文章对您有用,扫一下支付宝的红包,不胜感激!

欢迎加入QQ群进行技术交流:656897351(各种技术、招聘、兼职、培训欢迎加入)

Leave a Reply Cancel reply

You must be logged in to post a comment.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK