【发布时间】:2016-03-05 22:16:34
【问题描述】:
比如我想获取这个文件夹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 fetch,但这有点违背了稀疏结帐的目的,我的互联网很慢而且回购很大。我怎样才能获得带有分支 2.7 的子目录?谢谢!
这是在 windows8 和 git bash 上
编辑:
如果我跑
git pull --depth=1 origin 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 origin 4.8
那个文件夹util/qlalr/examples/lambda很小,但是运行最后一条命令的时候还是很慢,可以避免吗?
edit2:我意识到当前的 git 无法做到这一点。但我现在唯一剩下的问题是为什么git pull --depth=1 origin 2.7 不尊重稀疏结帐配置?
【问题讨论】: