我如何检出与指定的分支和稀疏检出一个巨大的git代码库的子direcotry? [英] How do I checkout a sub direcotry in a huge git repo with specified branch and with sparse checkout?

查看:632
本文介绍了我如何检出与指定的分支和稀疏检出一个巨大的git代码库的子direcotry?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我希望得到这个文件夹 https://github.com /python/cpython/tree/2.7/Tools/freeze

for example, I want to get this folder https://github.com/python/cpython/tree/2.7/Tools/freeze

我跑的命令是:

mkdir python
cd python
git init
git remote add origin https://github.com/python/cpython.git
git config core.sparsecheckout true
echo "Tools/freeze/*" >> .git/info/sparse-checkout

# find remote branches
git remote show origin

# this works and pulls only that folder
git pull --depth=1 origin master

# but this doesn't, why?
git pull --depth=1 origin 2.7

# but how do I switch to remote 2.7 branch?
git checkout --track -b 2.7 origin/2.7
fatal: Cannot update paths and switch to branch '2.7' at the same time.
Did you intend to checkout 'origin/2.7' which can not be resolved as commit?

我读的地方,我需要运行一个 git的结帐前取,但它那种战胜稀疏结帐的目的,我的互联网是缓慢和债券回购是巨大的。我怎么能只得到与分行2.7这个子目录?谢谢!

I read somewhere I need to run a git fetch before checkout, but it kind of defeat the purpose of sparse checkout, my internet is slow and repo is huge. How can I just get that subdirectory with branch 2.7 ? Thanks!

这是对Windows8的和Git的bash

This is on windows8 and git bash

编辑:
如果我跑
混帐拉--depth = 1原产地2.7 这将拉动2.7远程分支,但它也带来了其他所有文件到我的工作目录中,而如果我跑在主分支的git拉--depth = 1主产地,它不仅带来了工具/冻结目录?为什么会这样?

edit: if I ran git pull --depth=1 origin 2.7 it will pull remote 2.7 branch but it also brings every other files into my working directory, while if I ran git pull --depth=1 origin master, it only brings Tools/freeze directory in master branch ? why is this happening ?

另外一个例子:

mkdir qt
cd qt
git init
git remote add origin https://github.com/qtproject/qt.git
git config core.sparsecheckout true
echo util/qlalr/examples/lambda/* >> .git/info/sparse-checkout
git pull --depth=1 origin 4.8

该文件夹 UTIL / qlalr /例子/λ是非常小的,但是当它运行的最后一个命令,它仍然是缓慢的,可以这样可以避免?

That folder util/qlalr/examples/lambda is very small, but when it run the last command, it is still slow, can this be avoided ?

EDIT2:我意识到,这是不可能与当前的git。但我的唯一留下现在的问题是,为什么混帐拉--depth = 1原产地2.7 不尊重稀疏检出配置?

edit2: I realized that this is not possible with current git. but my only left question now is why git pull --depth=1 origin 2.7 doesn't respect sparse checkout config?

推荐答案

您结账失败,因为拉(从而获取)明确的参考取的只有的那个裁判,所以你的初始引入后,你回购了仅裁判/头/主参/遥控器/产地/主,都在同一指向提交。 2.7结帐没有工作,因为你的回购没有叫这个名字什么。

Your checkout failed because pulling (and hence fetching) an explicit ref fetches only that ref, so after your initial pull your repo had only refs/heads/master and refs/remotes/origin/master, both pointing at the same commit. Checkout of 2.7 didn't work because your repo didn't have anything by that name.

拉​​做了合并,而额外的内容的git拉出身2.7 把你的worktree是有冲突的解决,合并不能确定正确的结果,所以你必须至。你会看到,不是所有的工具目录外签出,只有冲突的文件。我不知道如何与浅合并获取和稀疏结账应整体表现,但要求解决冲突肯定是在这里做的唯一的事情。

Pull does a merge, and the extra content git pull origin 2.7 put in your worktree is there for conflict resolution, merge can't determine the correct results so you have to. You'll see that not everything outside the Tools directory is checked out, only the conflicted files. I'm not sure how merge with a shallow fetch and sparse checkout should behave overall, but asking for conflict resolution is surely the only thing to do here.

做一个浅浅的一REF取是轻量级的混帐获得,如果一次性使用的带宽是真的亲爱的,你可以克隆到一个EC2实例并标记特定的树。

Doing a shallow one-ref fetch is as lightweight as git gets, if one-off bandwidth use is really that dear you could clone to an ec2 instance and tag a particular tree.

这篇关于我如何检出与指定的分支和稀疏检出一个巨大的git代码库的子direcotry?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆