问题描述
使用 Git 1.7 中的新稀疏结帐功能.0,是否可以像在SVN中那样获取子目录的内容?我找到了 this example,但它保留了完整目录结构体.想象一下,我只想要perl"目录的内容,而没有名为perl"的实际目录.
With the new sparse checkout feature in Git 1.7.0, is it possible to just get the contents of a subdirectory like how you can in SVN? I found this example, but it preserves the full directory structure. Imagine that I just wanted the contents of the 'perl' directory, without an actual directory named 'perl'.
-- 编辑 --
示例:
我的git仓库包含以下路径
My git repository contains the following paths
repo/.git/
repo/perl/
repo/perl/script1.pl
repo/perl/script2.pl
repo/images/
repo/images/image1.jpg
repo/images/image2.jpg
repo/doc/
repo/doc/readme.txt
repo/doc/help.txt
我想要的是能够从上述存储库中生成此布局:
What I want is to be able to produce from the above repository this layout:
repo/.git/
repo/script1.pl
repo/script2.pl
不过目前的稀疏结账功能,好像只能得到
However with the current sparse checkout feature, it seems like it is only possible to get
repo/.git/
repo/perl/script1.pl
repo/perl/script2.pl
这不是我想要的.
推荐答案
您仍然需要克隆整个存储库,其中将包含所有文件.您可以使用 --depth
标志仅检索有限数量的历史记录.
You still need to clone the whole repository, which will have all the files. You could use the --depth
flag to only retrieve a limited amount of history.
一旦存储库被克隆,读取树技巧会将您对存储库的视图"限制为仅位于 .git/info/sparse-checkout
文件中的那些文件或目录.
Once the repository is cloned, the read-tree trick limits your "view" of the repository to only those files or directories that are in the .git/info/sparse-checkout
file.
我写了一个快速脚本来帮助管理稀疏性,因为目前它有点不友好:
I wrote a quick script to help manage the sparseness, since at the moment it is a bit unfriendly:
#!/bin/sh
echo > .git/info/sparse-checkout
for i in "$@"
do
echo "$i" >> .git/info/sparse-checkout
done
git read-tree -m -u HEAD
如果将此脚本以git-sparse.sh
的形式保存到调用git --exec-path
报出的路径中,则可以运行git sparsefoo/bar/
仅检出" foo 和 bar 目录,或 git sparse '*'
重新获取所有内容.
If you save this script as git-sparse.sh
into the path reported by calling git --exec-path
, then you can run git sparse foo/ bar/
to only "checkout" the foo and bar directories, or git sparse '*'
to get everything back again.
这篇关于Git 1.7.0 中的稀疏结帐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!