如何让Git克隆到当前目录

当尝试使用Git克隆到已存在的当前目录时,可能会遇到'致命:目的地路径'.'已存在且不是空目录'的错误。确保目录为空,并使用'git clone .'来克隆。如果目录已为空,但仍然收到错误,可以考虑使用'mv -f'强制移动文件。另一种方法是创建一个.git文件,但这可能并不总是等同于常规的克隆操作。
摘要由CSDN通过智能技术生成

本文翻译自:How to get Git to clone into current directory

I'm doing: 我正在做:

git clone ssh://user@host.com/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 ? 为了将该项目克隆到当前目录,我在这里缺少什么?


#1楼

参考:https://stackoom.com/question/fOGW/如何让Git克隆到当前目录


#2楼

Improving on @GoZoner's answer: 改进@ GoZoner的答案:

git clone <repository> foo; shopt -s dotglob nullglob; mv foo/* .; rmdir foo

The shopt command is taken from this SO answer and changes the behavior of the 'mv' command on Bash to include dotfiles, which you'll need to include the .git directory and any other hidden files. shopt命令取自此SO答案并更改Bash上'mv'命令的行为以包括dotfiles,您需要包含.git目录和任何其他隐藏文件。

Also note that this is only guaranteed to work as-is if the current directory (.) is empty, but it will work as long as none of the files in the cloned repo have the same name as files in the current directory. 另请注意,如果当前目录(。)为空,则只保证按原样运行,但只要克隆的repo中的所有文件都与当前目录中的文件同名,它就会起作用。 If you don't care what's in the current directory, you can add the -f (force) option to the 'mv' command. 如果您不关心当前目录中的内容,可以在“mv”命令中添加-f(强制)选项。


#3楼

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

#4楼

Solution: On this case, the solution was using the dot , so: rm -rf .* && git clone ssh://user@host.com/home/user/private/repos/project_hub.git . 解决方案:在这种情况下,解决方案是使用dot ,所以: rm -rf .* && git clone ssh://user@host.com/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,评论如下。


#5楼

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/config file which is equivalent to the one I get when doing a clone. 在我的例子中,这会生成一个.git/config文件,它等同于我在进行克隆时获得的文件。


#6楼

simply put a dot next to it 只需在它旁边放一个点

git clone git@github.com: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检查),否则命令将失败。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值