如何让 Git 克隆到当前目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9864728/
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 13:18:57  来源:igfitidea点击:

How to get Git to clone into current directory

gitgit-clone

提问by MEM

I'm doing:

我正在做:

git clone ssh://[email protected]/home/user/private/repos/project_hub.git ./

I'm getting:

我越来越:

Fatal: destination path '.' already exists and is not an empty directory.

致命:目标路径“.” 已经存在并且不是空目录。

I know path . already exists. And I can assure that directory IS empty. (I do ls inside and I see nothing!)

我知道路径。已经存在。我可以保证目录是空的。(我在里面做,我什么也没看到!)

What am I missing here in order to clone that project into the current directory ?

为了将该项目克隆到当前目录中,我在这里缺少什么?

采纳答案by MEM

Solution: On this case, the solution was using the dot, so: rm -rf .* && git clone ssh://[email protected]/home/user/private/repos/project_hub.git .

解决方案:在这种情况下,解决方案是使用dot,因此:rm -rf .* && git clone ssh://[email protected]/home/user/private/repos/project_hub.git .

rm -rf .* &&may be omitted if we are absolutely sure that the directory is empty.

rm -rf .* &&如果我们绝对确定目录为空,则可以省略。

Credits go to: @James McLaughlin on comments below.

致谢:@James McLaughlin 在下面的评论中。

回答by Roshan Pal

simply put a dot next to it

只需在它旁边放一个点

git clone [email protected]:user/my-project.git .

From git help clone:

来自git help clone

Cloning into an existing directory is only allowed if the directory is empty.

仅当目录为空时才允许克隆到现有目录。

So make sure the directory is empty (check with ls -a), otherwise the command will fail.

因此,请确保目录为空(使用 进行检查ls -a),否则该命令将失败。

回答by Andre Holzner

The following is probably not fully equivalent to a clone in all cases but did the trick for me:

以下可能并不完全等同于所有情况下的克隆,但对我有用:

git init .
git remote add -t \* -f origin <repository-url>
git checkout master

In my case, this produces a .git/configfile which is equivalent to the one I get when doing a clone.

就我而言,这会生成一个.git/config文件,该文件与我在进行克隆时得到的文件相同。

回答by ambes

@Andrew has answered it clearly here. But as simple as this also works even if the directory is not empty:

@Andrew 已经在这里清楚地回答。但是,即使目录不为空,这也很简单:

git init .
git remote add origin <repository-url>
git pull origin master

回答by eckes

To be sure that you could clone the repo, go to any temporary directory and clone the project there:

为了确保您可以克隆 repo,请转到任何临时目录并在那里克隆项目:

git clone ssh://[email protected]/home/user/private/repos/project_hub.git

This will clone your stuff into a project_hubdirectory.

这会将您的内容克隆到一个project_hub目录中。

Once the cloning has finished, you could move this directory wherever you want:

克隆完成后,您可以将此目录移动到任何您想要的位置:

mv project_hub /path/to/new/location

This is safe and doesn't require any magical stuff around.

这是安全的,不需要任何神奇的东西。

回答by return1.at

git clone your-repo tmp && mv tmp/.git . && rm -rf tmp && git reset --hard

回答by NSukonny

Do

git clone https://[email protected]/user/projectname.git .

Directory must be empty

目录必须为

回答by Nick Grealy

Hmm... specifing the absolute current path using $(pwd)worked for me.

嗯......使用$(pwd)对我有用的指定绝对电流路径。

git clone https://github.com/me/myproject.git $(pwd)

git version:2.21.0

git 版本:2.21.0

回答by GoZoner

If the current directory is empty, then this will work:

如果当前目录为空,那么这将起作用:

git clone <repository> foo; mv foo/* foo/.git* .; rmdir foo

回答by Jakehao

In addition to @StephaneDelcroix's answer, before using:

除了@StephaneDelcroix 的回答,在使用之前:

git clone [email protected]/my-project.git .

make sure that your current dir is empty by using

通过使用确保您当前的目录为空

ls -a