简体   繁体   中英

git sparse checkout and shallow clone issue with github

Want to do a sparse checkout from a git repo (github.com). Update (this script works now - trick was to add "/" before pom.xml Made this bash script:

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

If I remove lines from echo "pom.xml"... and till echo "solr/*" >> .git/info/exclude

I get sub directories: bom elasticsearch jpa map web

But not parent pom.

If I add echo "pom.xml" >> .git/info/sparse-checkout

Then it gets everything (all sub directories). Not sure why?

Update 2:

Earlier was trying :

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

Meaning adding paths I want git not to checkout to the file .git/info/exclude but that file is for add and committing only not for checkout.

For checkout have to add to file .git/info/sparse-checkout like so:

!cassandra/

The code line:

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

does that.

Use "/pom.xml", otherwise files like solr/pom.xml are checked out, creating needed directories.

Also for path patterns that should not be ignored during checkout, put them in .git/info/sparse-checkout but precede with a bag (!), example: !cassandra/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM