例如,我想获取这个文件夹:https://github.com/python/cpython/tree/2.7/Tools/freeze
我运行的命令是:
我在某处读到了,在切换分支前需要先运行
我的系统是Windows8和Git Bash。
编辑: 如果我运行
另一个例子:
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
,它只会带入主分支中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
很小,但当运行最后一个命令时,仍然很慢,这可以避免吗?
编辑2:我意识到目前的 git 不支持此功能。但我现在唯一剩下的问题是为什么 git pull --depth=1 origin 2.7
不遵守稀疏检出配置?