如何在指定分支和稀疏结帐的情况下在一个巨大的git仓库中签出一个子目录? [英] How do I checkout a sub directory in a huge git repo with specified branch and with sparse checkout?

查看:161
本文介绍了如何在指定分支和稀疏结帐的情况下在一个巨大的git仓库中签出一个子目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我想获取此文件夹 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
echoTools / freeze / *>> .git / info / sparse-checkout

#找到远程分支
git远程显示来源

#这个工程并且只提取该文件夹
git pull --depth = 1来源大师

#但这不,为什么?
git pull --depth = 1原点2.7

#但是如何切换到远程2.7分支?
git checkout --track -b 2.7 origin / 2.7
致命:无法同时更新路径并切换到分支2.7。
您是否打算签出无法解析为提交的origin / 2.7?

我读了某处需要运行 git fetch

这是在windows8和git bash上的。b / b
$ b

编辑:
如果我运行
git pull --depth = 1来源2.7 它会拉远程2.7分支,但它也将其他所有文件放到我的工作目录中,而如果我运行 git pull --depth = 1 origin master ,它只会在master分支中引入 Tools / freeze 目录?为什么会发生这种情况?



另一个例子:

  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来源4.8

该文件夹 util / qlalr / examples / lambda 非常小,但是当它运行最后一条命令时,它仍然很慢,能否避免这种情况?



edit2:我意识到这对于当前的git是不可能的。但我现在唯一留下的问题是为什么 git pull --depth = 1 origin 2.7 不尊重稀疏结帐配置?

解决方案

您的结帐失败是因为拉取(并因此获取)显式的ref仅会提取 所以在你最初的时候,你的回购只有 refs / heads / master refs / remotes / origin / master 指着同一个提交。 2.7的结账不起作用,因为您的回购没有任何名称。



Pull执行合并,额外内容 git拉来源2.7 放在你的工作树中有冲突解决,合并不能确定正确的结果,所以你必须。您会看到,并非所有Tools目录外的所有内容都被签出,只有冲突的文件被签出。我不确定融合浅层提取和稀疏结账应该如何表现整体,但是要求解决冲突肯定是唯一要做的事情。



做一个浅层one-ref fetch的获取与git一样轻巧,如果一次性带宽使用真的很贵,那么您可以克隆到ec2实例并标记特定的树。


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

The command I ran was:

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?

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!

This is on windows8 and git bash

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 ?

another example:

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

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: 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?

解决方案

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.

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.

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仓库中签出一个子目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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