简体   繁体   English

Git仅提取存储库中的内容

[英]Git pull only contents of a repository

Is there a way to only git pull the contents of a repository without pulling the home folder? 有没有办法只用git提取存储库中的内容而不提取主文件夹? For example I have a bunch of files in a repository called "sample" but I only want to pull the contents of "sample" into my local repository called "local." 例如,我在名为“示例”的存储库中有一堆文件,但我只想将“示例”的内容拉入我的本地存储库“本地”。 I do not want to pull "sample" such that I get: local -> sample -> [contents]. 想像这样获取“样本”:本地->样本-> [内容]。 Is there a way to only pull the contents? 有没有办法只拉东西?

I'm asking because I am operating on a shared web server that requires that I place my content under a specific folder (and named certain file names within the folder). 我之所以这样问是因为我在共享Web服务器上运行,要求将我的内容放在特定的文件夹下(并在该文件夹内命名某些文件名)。

Thanks. 谢谢。

EDIT: I wasn't being quite clear before. 编辑:我之前不太清楚。 I'm working on a local machine such that I am only allowed to change the contents of my folder and not the contents of the folder that contains my folder. 我在本地计算机上工作,因此只能更改文件夹的内容,而不能更改包含我的文件夹的文件夹的内容。

Option 1:: 选项1::

git clone <repo_path> <folder name>

So in your case, it would be git clone sample.git local 因此,在您的情况下,它将是git clone sample.git local

Option 2:: 选项2:

The folder-name where local repo is present does not have to be the same as that of the remote. 存在本地存储库的文件夹名称不必与远程存储库的名称相同。

do a git clone ... 做一个git clone ...

git clone repo_pathOrURL

then rename the folder 然后重命名文件夹

So for instance you have sample.git as your remote repository, do 因此,例如,您将sample.git作为远程存储库,请执行

git clone sample.git

This will clone the repository in a folder called sample on your local machine. 这会将存储库克隆到本地计算机上名为sample的文件夹中。 Then just rename this folder to your liking, in your case local , and continue with the regular git pull and push. 然后,只需将该文件夹重命名为您喜欢的名称(在local情况下为),然后继续常规的git pull and push。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM