git稀疏结账和github的浅克隆问题

时间:2017-01-23 08:00:02

标签: git bash github sh

想要从git repo(github.com)进行稀疏结账。 更新(此脚本现在可用 - 技巧是在pom.xml之前添加“/” 制作了这个bash脚本:

ngOnInit

如果我从echo“pom.xml”中删除行...并且直到echo“solr / *”>>的.git /信息/排除

我得到子目录: bom elasticsearch jpa map web

但不是父母pom。

如果我添加     echo“pom.xml”>>的.git /信息/稀疏结账

然后它获取所有内容(所有子目录)。不确定为什么?

更新2:

早些时候正在尝试:

#!/bin/sh

export baseUrl=https://github.com/
export repoAc=spring-projects
export repo=spring-data-examples

#export baseUrl=https://github.com/
#export repoAc=tgkprog
#export repo=testGit

echo "Cd change to correct dir like ~/u/w/s/github/"
cd ~/u/w/s3/github/
if [ $? -eq 0 ]; then
    echo OK
else
    echo"FAIL: bad dir to cd to "
    exit 0
fi
echo "Have you edited this script? Else crl -c to stop now"
echo "you are at dir:"
pwd
echo "If exists contents of $repoAc/$repo :"
ls $repoAc/$repo
echo "1/2 will delete folder $repoAc/$repo ctrl-c to cancel. Press enter to continue"
read -rsp $'Press Ctrl-c to cancel or any other key to continue \n' -n1 key
echo "2/2 will delete folder $repo ctrl-c to cancel. Press enter to continue "
read -rsp $'Press Ctrl-c to cancel or any other key to continue \n' -n1 key
mkdir $repoAc
cd $repoAc
rm -fR ./$repo
git init $repo
cd $repo
if [ $? -eq 0 ]; then
    echo OK
else
    echo"FAIL: bad dir to cd to "
    exit 0
fi
# TODO if error stop here.
git remote add origin $baseUrl$repoAc/$repo
git config core.sparsecheckout true
echo "elasticsearch/*" >> .git/info/sparse-checkout
echo "/README.md" >> .git/info/sparse-checkout
#echo "h/" >> .git/info/sparse-checkout
#echo "s/" >> .git/info/sparse-checkout
echo "web/*" >> .git/info/sparse-checkout
echo "jpa/*" >> .git/info/sparse-checkout
echo "map/*" >> .git/info/sparse-checkout
echo "multi-store/*" >> .git/info/sparse-checkout
echo "/pom.xml" >> .git/info/sparse-checkout
#echo "!*/pom.xml" >> .git/info/sparse-checkout
#paths we do not want
echo "!no1/" >> .git/info/sparse-checkout
echo "!neo4j/" >> .git/info/sparse-checkout
echo "!cassandra/" >> .git/info/sparse-checkout
echo "!solr/" >> .git/info/sparse-checkout
git pull --depth=1 origin master 
#   wget https://raw.githubusercontent.com/spring-projects/spring-data-examples/master/pom.xml
echo "Done $repo"
ls -al

意思是添加路径我希望git不要签出文件.git / info / exclude,但该文件仅用于添加和提交,而不是用于签出。

结帐时必须添加到文件.git / info / sparse-checkout,如下所示:

  

!卡桑德拉/

代码行:

echo "cassandra/*" >> .git/info/exclude

那样做。

1 个答案:

答案 0 :(得分:1)

使用“/pom.xml”,否则会检出像solr / pom.xml这样的文件,创建所需的目录。

对于在结账时不应忽略的路径模式,请将它们放在.git / info / sparse-checkout中,但先于bag(!),例如: !卡桑德拉/