我在做:

git clone ssh://user@host.com/home/user/private/repos/project_hub.git ./

我得到:

致命:目标路径'。’已经存在,不是空的 目录中。

我知道路。已经存在。 我可以保证这个目录是空的。(我在里面,我什么都看不到!)

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


当前回答

进一步完善@phatblat的回答:

git clone --no-checkout <repository> tmp \
  && mv tmp/.git . \
  && rmdir tmp \
  && git checkout master

作为一行:

Git克隆——no-checkout <repository> TMP && mv TMP /。git。&& rmdir TMP && git checkout master

其他回答

Do

git clone https://user@bitbucket.org/user/projectname.git .

目录必须为空

使用$(pwd)指定绝对当前路径对我来说是可行的。

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

Git版本:2.21.0

需要空目录,根据票证说明。


更新2022:你现在可以使用。

i.e.

git clone https://github.com/me/myproject.git .

Git版本:2.36.1

改进@GoZoner的回答:

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

shopt命令取自这个SO答案,并将Bash上的'mv'命令的行为更改为包含dotfiles,您需要包括.git目录和任何其他隐藏文件。

还要注意,只有在当前目录(.)为空的情况下,这才保证正常工作,但只要克隆的repo中没有任何文件与当前目录中的文件具有相同的名称,它就可以正常工作。如果你不关心当前目录中有什么,你可以在'mv'命令中添加-f (force)选项。

我用它将一个repo复制到当前目录,当前目录不是空的。不一定是干净的生活,但它是在一个一次性的码头集装箱里:

git clone https://github.com/myself/myRepo.git temp
cp -r temp/* .
rm -rf temp

这里,我用cp -r代替mv,因为这样可以复制隐藏的文件和目录。然后使用rm -rf释放临时目录

shopt -s dotglob
git clone ssh://user@host.com/home/user/private/repos/project_hub.git tmp && mv tmp/* . && rm -rf tmp