您的位置:首页 > 其它

使用git下载项目下的单个文件或目录

2018-11-10 11:08 113 查看

因为svn是基于文件存储的,所以用svn可以方便地下载项目下的单个文件或目录,但是git是基于元数据存储的,因此操作会麻烦一些,要用到git的sparse checkout模式。步骤如下:

打开git bash,cd到本地项目目录(LocalPro/),创建一个空的本地仓库,把远程仓库的url(remoteURL)加入到config文件中去:

[code]cd LocalProj
git init
git remote add -f origin <remoteURL>

在config中设置sparse checkout模式为true:

[code]git config core.sparseCheckout true

把需要checkout(即需要下载的)文件或目录写入.git/info/sparse-checkout

[code]echo fileOrdir >> .git/info/sparse-checkout

然后下载

[code] git pull origin master

以一个例子完整说明整个过程。

假设之前已经通过git clone的方式把项目https://github.com/Yourens/decaf_PA2_2018完整地克隆到本地目录d:\PA2,之后远程仓库更新了https://github.com/Yourens/decaf_PA2_2018/tree/master/TestCases的内容,但是本地项目已经做了修改,不能重新git clone整个远程仓库,这时就需要单独clone远程的TestCases目录。git bash命令为

[code]cd /d/PA2
git init
git remote add -f  origin https://github.com/Yourens/decaf_PA2_2018.git
git config core.sparseCheckout true
echo 'TestCases' >> .git/info/sparse-checkout
git pull origin master

 

阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: