Git稀疏签出,用于简单的Web部署 [英] Git sparse checkout for simple web deployment
问题描述
我有这样的目录结构:
../dir1/dev/project1/...
/project2/...
/project3/...
/production/
我已将dev(及其所有子目录)检入git(和github).一切都很好.
I have dev (and all its sub directories) checked into git (and github). All is working well.
我想使用github通过检出(或拉入或其他方式)到生产目录来仅部署project2. (特别是,我想按标签签出.)因此这将导致../dir1/production/project2
I would like to use github to deploy only project2 by checking out (or pulling, or whatever) into my production directory. (And specifically, I want to check out by tag.) So this would result in ../dir1/production/project2
我不是git专家,但在网上读了一堆书,看来我想找的是稀疏结帐".我已经尝试在此处和此处.
I'm not a git expert but have read a bunch online and it seems that a 'sparse checkout' is what I'm after. I've tried various combinations of the instructions here and here and here.
我基本上做到了:
mkdir <repo> && cd <repo>
git init
git remote add –f <name> <url>
git config core.sparsecheckout true
echo /project2/ >> .git/info/sparse-checkout
当我执行git pull <remote> TAGNAME
时,我会得到fatal: The remote end hung up unexpectedly
.
When I do git pull <remote> TAGNAME
I get fatal: The remote end hung up unexpectedly
.
当我执行git checkout TAGNAME
时,我会得到error: Sparse checkout leaves no entry on working directory
.
When I do git checkout TAGNAME
I get error: Sparse checkout leaves no entry on working directory
.
我做错了什么?
推荐答案
啊哈-解决了它.问题在于,通过执行初始化操作,它正在创建一个空的存储库,因此我无法进行检出. (我不知道为什么拉不起作用.)
Aha - solved it. The problem was that by doing init it was creating an empty repository, so I couldn't do a checkout. (I don't know why the pull didn't work.)
相反,请执行克隆操作,但将-n参数用于不检出".这将克隆git存储库,但将您的工作树留空.然后设置稀疏签出.然后签出您想要的东西.
Instead, do a clone , but use the -n parameter for "no checkout". This clones the git repository but leaves your working tree empty. Then set up sparse checkout. Then checkout just what you want.
白色:
cd <parentdir>
git clone -n <url>
cd <repo_dir>
git remote add –f <name> <url>
git config core.sparsecheckout true
echo /<foldername>/ >> .git/info/sparse-checkout
git checkout <tagname>
这篇关于Git稀疏签出,用于简单的Web部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!