2017-01-23 109 views
2

想从git repo(github.com)做一个稀疏结账。 更新(这个剧本现在工作 - 诀窍是添加“/”前的pom.xml 提出这一bash脚本:git稀疏结账和github的浅克隆问题

#!/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 

如果我删除回声“的pom.xml”行......直等到回音“ Solr的/ *” git的>> /信息/排除

我得到子目录: BOM elasticsearch JPA地图网站

但不是父POM

如果我添加 回声 “的pom.xml” >> .git/info/spa rse-checkout

然后它得到一切(所有子目录)。不知道为什么?

更新2:

早些时候试图:

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

意义添加路径我想让Git不/信息/排除签的文件git的,但该文件是用于添加,只承诺不结帐。

对于检出必须添加到文件的.git /信息/稀疏结账像这样:

!卡桑德拉/

的代码行:

echo "!cassandra/" >>.git/info/sparse-checkout 

这是否。

+1

填充'git的/ info/exclude'在你的情况下没有意义;它在提交/添加时被考虑,但不在结账时 – max630

+1

'@echo off'用于批处理文件 - 对于shell脚本来说它不是必需的或有用的。 –

+0

@ max630是你的权利。需要在.git/info/sparse-checkout中的路径之前使用bang(!)标记为不包含。 – tgkprog

回答

1

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

而且于不应该在结帐时忽略路径模式,把他们的.git /信息/稀疏结账但有袋之前,例如(!)! 卡桑德拉/

+0

是的你的权利。我编辑了你的答案,以说明正确的方式来做出负面路径 – tgkprog

+1

默认情况下,如果没有写入'sparse-checkout'它没有签出。但是明确的总是更好 – max630