通过ssh git clone

标签 git git-clone

我有一个项目,我在上面创建了一个 git 存储库:

$ cd myproject  
$ git init  
$ git add .  
$ git commit  

我想在另一台机器上创建一个裸克隆:

$ cd ..  
$ git clone --bare myproject  ssh://user@server:/GitRepos/myproject.git  

我执行了克隆但没有打印任何答案。 我登录到服务器机器并试图查看文件是如何存储的。/GitRepos 路径是空的,所以我决定再次克隆:

$ git clone --bare myproject  ssh://user@server:/GitRepos/myproject.git

这次的答案是:

fatal: destination path 'ssh://user@server:/GitRepos/myproject.git' already exists and is not an empty directory.

但是我看到路径是空的。
这是怎么回事?

最佳答案

这可能与问题没有直接关系;但是我自己犯的一个错误,我在 OP 中看到,是 URL 规范 ssh://user@server:/GitRepos/myproject.git - 也就是说,你有一个冒号 : 和正斜杠 / 表示绝对路径。

然后我找到了Git clone, ssh: Could not resolve hostname – git , development – Nicolas Kuttler (因为这是我在 git 版本 1.7.9.5 上遇到的错误),注意:

The problem with the command I used initially was that I tried to use an scp-like syntax.

...这也是我的问题!所以基本上在 gitssh 中,你要么使用

  • ssh://username@host.xz/absolute/path/to/repo.git/ - 只是服务器上绝对路径的正斜杠
  • username@host.xz:relative/path/to/repo.git/ - 只是一个冒号(它不能有 ssh:// 作为 relative服务器上的路径(相对于服务器计算机上 username 的主目录)

希望这对某人有帮助,
干杯!

关于通过ssh git clone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6167905/

相关文章:

git - 使用git发布到网站

使用公共(public)私钥的 Git 克隆

git - git remote add 和 git clone 的区别

git - 使用 git clone 命令克隆时访问被拒绝

git - 在 Git 中推送提交时出现消息 'src refspec master does not match any'

git 不会推送到远程分支 "Everything up-to-date"

node.js - npm install 时发生致命坏对象错误

git - 在 git 中使克隆的存储库成为主存储库

git - 如何修改 git stash 中的消息?

java - 识别 git 存储库中的参数更改