git 克隆 GitHub 存储库的内容(不包括文件夹本身)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6224626/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 11:05:03  来源:igfitidea点击:

Clone contents of a GitHub repository (without the folder itself)

gitgithub

提问by mazlix

I'd like to git clonethe contents of a repository I have on GitHub. When I git clone(git@github:me/name.git...) I get a folder called name/and inside name I have my contents... How do I get JUST the contents?

我想要git clone我在GitHub 上的存储库的内容。当我git clone(git@github:me/name.git...) 我得到一个名为的文件夹name/和里面的名字我有我的内容......我如何获得内容?

回答by Mark Longair

If the current directory is empty, you can do that with:

如果当前目录是空的,你可以这样做:

git clone git@github:me/name.git .

(Note the .at the end to specify the current directory.) Of course, this also creates the .gitdirectory in your current folder, not just the source code from your project.

(注意.最后指定当前目录。)当然,这也会.git在您的当前文件夹中创建目录,而不仅仅是项目的源代码。

This optional [directory]parameter is documented in the git clonemanual page, which points out that cloning into an existing directory is only allowed if that directory is empty.

这个可选[directory]参数记录在git clone手册页中,它指出只有当目录为空时才允许克隆到现有目录中。

回答by John Little

Unfortunately, this doesn't work if there are other, non-related directories already in the same dir. Looking for a solution. The error message is: "fatal: destination path '.' already exists...".

不幸的是,如果同一个目录中已经存在其他不相关的目录,这将不起作用。正在寻找解决方案。错误消息是:“致命:目标路径'。' 已经存在...”。

The solution in this case is:

这种情况下的解决办法是:

git init
git remote add origin [email protected]:me/name.git
git pull origin master

This recipe works even if there are other directories in the one you want to checkout in.

即使您要签入的目录中有其他目录,此方法也有效。

回答by Tomá? Zemanovi?

If the folder is not empty, a slightly modified version of @JohnLittle's answer worked for me:

如果文件夹不为空,@JohnLittle 答案的稍微修改版本对我有用:

git init
git remote add origin https://github.com/me/name.git
git pull origin master

As @peter-cordes pointed out, the only difference is using https protocol instead of git, for which you need to have SSH keys configured.

正如@peter-cordes 所指出的,唯一的区别是使用 https 协议而不是 git,为此您需要配置 SSH 密钥

回答by Laurent Pireyn

You can specify the destination directory as second parameter of the git clonecommand, so you can do:

您可以指定目标目录作为git clone命令的第二个参数,因此您可以执行以下操作:

git clone <remote> .

This will clone the repository directly in the current local directory.

这将直接在当前本地目录中克隆存储库。

回答by Diego Santa Cruz Mendezú

this worker for me

这个工人对我来说

git clone <repository> .

回答by fingerman

to clone git repo into the currentand emptyfolder (no git init) and if you do not use ssh:

以克隆的git回购到当前文件夹(无git init),如果你不使用ssh:

git clone https://github.com/accountName/repoName.git .