博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何让Git克隆到当前目录
阅读量:2290 次
发布时间:2019-05-09

本文共 2503 字,大约阅读时间需要 8 分钟。

本文翻译自:

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楼

参考:


#2楼

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

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

The shopt command is taken from 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命令取自并更改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 
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检查),否则命令将失败。

转载地址:http://pvcnb.baihongyu.com/

你可能感兴趣的文章
YUM安装PHP5.6
查看>>
YUM源安装MySQL5.7
查看>>
Tomcat日志切割cronolog
查看>>
glibc-2.14安装
查看>>
升级openssl zlib版本 安装nginx
查看>>
ab压力测试
查看>>
SVN指定端口启动
查看>>
网站访问速度一般检查参数
查看>>
编译安装过程
查看>>
HTTP常见返回码信息
查看>>
WEB集群session处理方案
查看>>
JDK命令行(jps、jstat、jinfo、jmap、jhat、jstack、jstatd、hprof)与JConsole
查看>>
JAVA 对象访问: 句柄和指针
查看>>
dubbo 报错:java.lang.NoClassDefFoundError: org/I0Itec/zkclient/exception/ZkNoNodeException
查看>>
logback的使用和logback.xml详解
查看>>
Linux 快捷键
查看>>
JPA 联合主键配置
查看>>
ObjectAlreadyExistsException:Unable to store Job : '*', because one already exists with thi s ident
查看>>
这些大厂面试真题你能答出来,年薪至少30-50W,想不想挑战一下?
查看>>
携程T7用637页PDF,解读十余热门技术领域,八场携程技术沙龙干货
查看>>