我有一个项目,我创建了一个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

这一次的答案是:

ssh://user@server:/GitRepos/myproject。Git目录已经存在,并且不是空目录。

但我看到小路上空无一人。 这是怎么回事?


当前回答

围棋 101:

Git是一个去中心化的版本控制系统。你不需要服务器来启动和运行git。你可能还是想这么做,因为它看起来很酷,对吧?(如果你想在多台电脑上处理一个项目,它也很有用。)

所以要让“服务器”运行,你需要运行git init——bare <your_project>。Git会创建一个空的存储库,然后你可以将它导入到你的机器上,而不必在. Git目录下的配置文件中瞎折腾。

After this you could clone the repo on your clients as it is supposed to work, but I found that some clients (namely git-gui) will fail to clone a repo that is completely empty. To work around this you need to run cd <your_project>.git && touch <some_random_file> && git add <some_random_file> && git commit && git push origin master. (Note that you might need to configure your username and email for that machine's git if you hadn't done so in the past. The actual commands to run will be in the error message you get so I'll just omit them.)

因此,在这一点上,你可以简单地运行git clone <user>@<server>:<relative_path><your_project>.git将存储库克隆到任何机器。(正如其他人指出的那样,如果使用绝对路径,可能需要在它前面加上ssh://。)这假设您已经可以从客户端登录到服务器。(如果你想把很多东西推送到远程服务器上,你还可以为ssh设置配置文件和密钥。)

相关链接: 这基本上告诉了你你需要知道的。 这是为那些知道git的基本工作原理但有时忘记确切语法的人准备的。

其他回答

对于GitHub上的存储库,请尝试:

git clone ssh://git@github.com/<user>/<repository name>.git

通过ssh设置git克隆参见:

生成SSH密钥并在“帐户设置-> SSH密钥”中添加生成的密钥 SSH克隆

我说: “/GITREPOSITORIES/RepoA”“ssh://luc@EERSTENASDS119J/volume1/RepoA” 结果: fatal:目标路径“ssh://luc@EERSTENASDS119J/volume1/RepoA”已经存在,并且不是空目录。

系统在当前路径下创建了一个目录ssh://luc@EERSTENASDS119J/volume1/RepoA。

所以git克隆没有解释URL规范。 使用亚历克的变通方法。

git克隆服务器:Example/ project .git

围棋 101:

Git是一个去中心化的版本控制系统。你不需要服务器来启动和运行git。你可能还是想这么做,因为它看起来很酷,对吧?(如果你想在多台电脑上处理一个项目,它也很有用。)

所以要让“服务器”运行,你需要运行git init——bare <your_project>。Git会创建一个空的存储库,然后你可以将它导入到你的机器上,而不必在. Git目录下的配置文件中瞎折腾。

After this you could clone the repo on your clients as it is supposed to work, but I found that some clients (namely git-gui) will fail to clone a repo that is completely empty. To work around this you need to run cd <your_project>.git && touch <some_random_file> && git add <some_random_file> && git commit && git push origin master. (Note that you might need to configure your username and email for that machine's git if you hadn't done so in the past. The actual commands to run will be in the error message you get so I'll just omit them.)

因此,在这一点上,你可以简单地运行git clone <user>@<server>:<relative_path><your_project>.git将存储库克隆到任何机器。(正如其他人指出的那样,如果使用绝对路径,可能需要在它前面加上ssh://。)这假设您已经可以从客户端登录到服务器。(如果你想把很多东西推送到远程服务器上,你还可以为ssh设置配置文件和密钥。)

相关链接: 这基本上告诉了你你需要知道的。 这是为那些知道git的基本工作原理但有时忘记确切语法的人准备的。

您需要在您调用的服务器上运行clone命令。但是我打赌你没有在你的本地客户端上运行ssh服务器,所以不管怎样这都行不通。建议你遵循这个方法(检查手册,因为我是凭记忆这么做的)

登录到服务器机器。 使用git init——bare创建一个裸回购 在客户端机器上,您可以将回购推到服务器。git远程添加source ssh://user@server:/GitRepos/myproject。Git后面跟着Git push origin master