问题
Some background: My company's service model began as an appliance-based server model. We would send our client a server with Windows Server 2003/2008 on it, pre-loaded with a webserver and our software. We're moving all of the client-specific configuration to a Git repository, and using sparse-checkout to make each server only contain what's necessary for the client's software to function properly.
While setting up sparse-checkout, we've run into a huge inconsistency. We'll do
git clone git@github.com:ourclientconfigrepo.git .
git config core.sparsecheckout true
echo www.thisclient.com/ > .git/info/sparse-checkout
git read-tree -m -u HEAD
The expected result would be
ls
www.thisclient.com/
but we get
ls
www.thisclient.com/
www.randomclient1.com/
www.randomclient2.com/
www.randomclient3.com/
I've tried multiple times, in a new directory each time, and the issue has happened each time. My ju-git-su fails me here. We're using git version 1.8.1.msysgit.1.
Thanks for your help, let me know if I need to supply more information.
---EDIT 1---
Clarification: The repository is nothing but our client's configuration directories. Each client has a different directory in the repository, and we're trying to sparse-checkout on each client's individual server, so we're trying to exclude everything except for the client in question.
---EDIT 2---
Just an update, turns out it was something wonky with Windows folder permissions, and Git was trying to delete non-empty directories. Fixed it by deleting the empty folders. Thanks for any and all attempts at helping!
回答1:
A partial solution: According to git-read-tree(1), you can exclude specific files by putting a ! in front of the file name. This may be a miswrite, however (meaning that that's for directories as well, not files).
I'll continue investigating.
According to https://stackoverflow.com/a/11222033/1210278, you can manually mark directories with git update-index --skip-worktree www.randomclient1.com/
.
https://stackoverflow.com/a/9575837/1210278 implies that exclusion is only for directories, and says that there are some bugs with it.
回答2:
Your clone operation is not the correct way to create a sparse clone. Instead of:
git clone ...
You should use this sequence:
mkdir repo ; cd repo ; git init
git remote add -f origin <url>
git config core.sparsecheckout true
echo <dir1>/ >> .git/info/sparse-checkout
echo <dir2>/ >> .git/info/sparse-checkout
echo <dir3>/ >> .git/info/sparse-checkout
git pull origin master
来源:https://stackoverflow.com/questions/15619112/why-does-git-sparse-checkout-leave-behind-directories