首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >稀疏结帐对跟踪文件起作用吗?

稀疏结帐对跟踪文件起作用吗?
EN

Stack Overflow用户
提问于 2020-04-14 18:04:22
回答 1查看 233关注 0票数 0

我的本地和远程服务器都是centos 7。

我用git版本1.8.3.1跟踪本地回购中的README.md,当我修改README.md并推送到远程裸回购时,我不希望README.md被检出。

在远程回购中,git版本为2.16.6,我将post-receive设置为:

代码语言:javascript
复制
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设置为:

代码语言:javascript
复制
/*
!/README.md

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

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

代码语言:javascript
复制
!/README.md
/*

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

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-04-14 19:34:19

是时候玩点对点了。下面是我的测试设置,它显示了当我doit时稀疏签出正常工作。这是我的终端缓冲区中的一个直接的c&p,复制函数定义,然后说是doit

代码语言:javascript
复制
$ 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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61214266

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档