稀疏结帐是否对跟踪文件起作用?

Does sparse-checkout act on tracked file?

我的本地和远程服务器都是centos 7.
我使用 git 版本 1.8.3 在本地回购中跟踪 README.md。1.When 我修改了 README.md 并推送到远程裸回购,我不想要 README.md有待签出。
在远程仓库中,git 版本是 2.16.6,我设置 post-receive 如下:

while read oldrev newrev ref
do
     if [[ $ref = refs/heads/"$BRANCH" ]];
        then
        git --work-tree="$DEPLOY_DIR"  --git-dir="$GIT_DIR" checkout -f
     fi
done

在远程仓库中,我设置 sparse-checkout 如下:

/*
!/README.md

我发现 README.md 还在那里,没有修改。

然后,我修改sparse-checkout如下:

!/README.md
/*

我得到了remote: error: Entry 'README.md' not uptodate. Cannot merge.

哪个sparse-checkout是正确的?问题出在哪里?

是时候找不同了。这是我的测试设置,它显示当我 doit 时稀疏结帐正常工作。这是我的终端缓冲区中的直接 c&p,复制函数定义并说 doit.

$ doit () { 
set -x
git init testlocal; cd $_
git commit --allow-empty -m-
git clone --bare . ../testremote; cd $_
git config core.sparsecheckout true
mkdir -p hooks info worktree
printf %s\n /\* \!/README.md >info/sparse-checkout
tee hooks/post-receive <<'EOD'; chmod +x $_
while read oldrev newrev ref; do
        if [[ $ref = refs/heads/master ]]; then
                git --work-tree="$GIT_DIR/worktree" checkout -f
        fi
done
EOD
cd -
touch notREADME.md README.md
git add .; git commit -m-
git push ../testremote master
ls ../testremote/worktree
set +x
}
$ doit
+ git init testlocal
Initialized empty Git repository in /home/jthill/src/snips/testlocal/.git/
+ cd testlocal
/home/jthill/src/snips/testlocal
+ git commit --allow-empty -m-
[master (root-commit) 6ed44ec] -
+ git clone --bare . ../testremote
Cloning into bare repository '../testremote'...
done.
+ cd ../testremote
+ git config core.sparsecheckout true
+ mkdir -p hooks info worktree
+ printf '%s\n' '/*' '!/README.md'
+ tee hooks/post-receive
while read oldrev newrev ref
do
     if [[ $ref = refs/heads/master ]];
        then
        git --work-tree="$GIT_DIR/worktree" checkout -f
     fi
done
+ chmod +x hooks/post-receive
+ cd -
/home/jthill/src/snips/testlocal
+ touch notREADME.md README.md
+ git add .
+ git commit -m-
[master 64f5358] -
 2 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 README.md
 create mode 100644 notREADME.md
+ git push ../testremote master
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 4 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 240 bytes | 240.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To ../testremote
   6ed44ec..64f5358  master -> master
+ ls --color=auto ../testremote/worktree
notREADME.md
+ set +x