如何将git repo子目录检出到当前目录? [英] How to checkout git repo subdirectory into current directory?
问题描述
有一个具有目录结构的远程仓库:
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屋!