如何将git repo子目录检出到当前目录? [英] How to checkout git repo subdirectory into current directory?

查看:181
本文介绍了如何将git repo子目录检出到当前目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个具有目录结构的远程仓库:

There is a remote repo with directory structure:

-directory1
    -file1_1
    -file1_2
    ...
-directory2
    -file2_1
    -file2_2
    ...

我在虚拟主机上有一个文件夹,其名称为"/path/public_html".

I have a folder on a web hosting with a custom name, say, "/path/public_html".

如何在虚拟主机上设置git,以便我的"public_html"跟踪远程存储库的子目录"directory2"?

How do I set up git on the web hosting, so my "public_html" tracks a subdirectory "directory2" of a remote repo?

因此,换句话说,我想在网络托管上执行某种形式的git命令,并将public_html更新为"directory2"的最新内容.如果有帮助,我不在乎推迟从虚拟主机回购回购邮件.

So, in other words, I want to execute some form of git command on the web hosting and update public_html to the latest content of "directory2". I don't care about pushing back to repo from web hosting, if it helps.

推荐答案

您不能直接克隆directory2 内容,只能克隆directory2 及其的内容,这意味着您磁盘上总是有一个directory2/文件夹.

You cannot clone directly directory2 content, only directory2 and its content, meaning you always have a directory2/ folder on your disk.

如果要在public_html中看到directory2内容(表示不是 public_html/directory2/...),则需要符号链接.

If you want to see directory2 content in public_html (meaning not public_html/directory2/...), then you need a symlink.

话虽如此,您仍然可以克隆和检出仅 directory2文件夹,而不是如"是否可以在不先检出整个存储库的情况下进行稀疏检出?"

That being said, you can still clone and checkout only directory2 folder, instead of cloning the full repo, as described in "Is it possible to do a sparse checkout without checking out the whole repository first?"

也就是说:

git init /a/path
cd /a/path
git config core.sparseCheckout true
git remote add -f origin /url/remote/repo
echo "directory2/" > .git/info/sparse-checkout
git checkout [branchname] # ex: master

这将提供一个a/path/directory2文件夹,而您的public_html不能提供symlink文件夹.

That would give a a/path/directory2 folder, than your public_html can symlink to.

如果public_html中的directory2文件夹不打扰您,则可以在public_html中而不是a/path重复上述命令.

If having a directory2 folder in public_html does not bother you, then you could repeat the above commands in public_html instead of a/path.

这篇关于如何将git repo子目录检出到当前目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆