想从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
这是否。
填充'git的/ info/exclude'在你的情况下没有意义;它在提交/添加时被考虑,但不在结账时 – max630
'@echo off'用于批处理文件 - 对于shell脚本来说它不是必需的或有用的。 –
@ max630是你的权利。需要在.git/info/sparse-checkout中的路径之前使用bang(!)标记为不包含。 – tgkprog