想從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