我有一个项目,我创建了一个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的基本工作原理但有时忘记确切语法的人准备的。
围棋 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的基本工作原理但有时忘记确切语法的人准备的。