Git sparse checkout for simple web deployment

醉酒当歌 提交于 2019-12-04 21:24:35

问题


I have a directory structure like this:

../dir1/dev/project1/...
           /project2/...
           /project3/...
       /production/

I have dev (and all its sub directories) checked into git (and github). All is working well.

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

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.

Basically I did:

mkdir <repo> && cd <repo>
git init
git remote add –f <name> <url>
git config core.sparsecheckout true
echo /project2/ >> .git/info/sparse-checkout

When I do git pull <remote> TAGNAME I get fatal: The remote end hung up unexpectedly.

When I do git checkout TAGNAME I get error: Sparse checkout leaves no entry on working directory.

What am I doing wrong?


回答1:


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.)

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.

To whit:

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>


来源:https://stackoverflow.com/questions/15827117/git-sparse-checkout-for-simple-web-deployment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!