Git 存储库从一台机器到另一台机器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2090809/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git repository from one machine to another
提问by Shaun F
So I have a git repository that i pulled at one point and that repository resides on a server. I don't have access to the original repository that I pulled it from. How do i get the code from the existing server to another computer?
所以我有一个 git 存储库,我曾经拉过它,并且该存储库驻留在服务器上。我无权访问我从中提取的原始存储库。如何将代码从现有服务器获取到另一台计算机?
EDIT 1: So here's what it looks like:
编辑 1: 所以这是它的样子:
- COMPUTER A: The git repository that I originally checked out from. I don't have access to this anymore.
- COMPUTER B: A shared server that I have the code checked out on.
- COMPUTER C: A Local laptop.
- 计算机 A:我最初检出的 git 存储库。我再也无法访问这个了。
- 计算机 B:我已检出代码的共享服务器。
- 计算机 C:本地笔记本电脑。
Can i just do a simple copy of that directory without using git, or can I use git to clone if from B to C?
我可以在不使用 git 的情况下对该目录进行简单的复制,或者如果从 B 到 C,我可以使用 git 进行克隆吗?
采纳答案by Igor Zevaka
You can either pull from the network location or copy the entire directory(containing .git folder) accross to the other computer.
您可以从网络位置拉取或将整个目录(包含 .git 文件夹)复制到另一台计算机。
回答by
This is achieved by creating a clone of the repository that is on COMPUTER B, by running the command git clone
on COMPUTER C, where you want the cloned repository to be created. Cloning in git can be done using multiple protocols, including ssh, https, git; and these require an appropriate setup for the git clone
command to succeed.
这是通过git clone
在计算机 C 上运行命令来创建位于计算机 B上的存储库的克隆来实现的,您希望在其中创建克隆的存储库。在git中克隆可以使用多种协议完成,包括ssh、https、git;这些需要适当的设置才能使git clone
命令成功。
The easiest approach is to start the git server on COMPUTER B using this command:
最简单的方法是使用以下命令在计算机 B 上启动 git 服务器:
> git daemon
For help with the above command, run git help daemon
如需上述命令的帮助,请运行 git help daemon
Then place a marker file in the .git folder of the repository on COMPUTER B to grant permission to the git server to run the clone command on that repository. This is done by:
然后在计算机 B 上存储库的 .git 文件夹中放置一个标记文件,以授予 git 服务器在该存储库上运行克隆命令的权限。这是通过以下方式完成的:
> cd <repository root>/.git
> touch git-daemon-export-ok
Now, from a terminal on COMPUTER C, run the following commands:
现在,从计算机 C 上的终端运行以下命令:
> cd <folder in which to create the cloned repository>
> git clone git://<ip address of COMPUTER B>/<full path of the repository on COMPUTER B>
This will create the cloned repository on COMPUTER C.
这将在计算机 C 上创建克隆的存储库。
回答by Matt Enright
You can just clone it from the server, assuming you have access to where the clone is stored - the power of distribution ;)
您可以从服务器克隆它,假设您可以访问存储克隆的位置 - 分发的力量;)
回答by Sdra
You can run from computer C:
您可以从计算机 C 运行:
git clone username@computer_B:path/to/root/of/repository
assuming that computer B has a ssh server running. Otherwise other protocols are supported (file://, http://, \\computer_B (NetBios), ...)
假设计算机 B 有一个 ssh 服务器正在运行。否则支持其他协议(file://、http://、\\computer_B (NetBios)、...)
回答by luckytaxi
You mean you wanna clone it to a different computer?
你的意思是你想把它克隆到另一台电脑上?
How about:
怎么样:
git clone ssh://myserver/path/to/myproject.git
回答by Pjotrs Osnovskis
If anyone has any issues with cloning, I used simply this, on the machine you want app to be cloned to:
如果有人对克隆有任何问题,我只是在您希望将应用程序克隆到的机器上使用了这个:
- in CMD go to folder where you want your app to be cloned to, for example
cd C:/my_apps/
- login to github and go to app you want to clone, press green button "Clone or Download", you will see SSH link, copy it.
- in CMD run
git clone [email protected]:user/my-app.git
(use SSH link you copied)
- 在 CMD 中,转到您希望将应用程序克隆到的文件夹,例如
cd C:/my_apps/
- 登录github并转到要克隆的应用程序,按绿色按钮“克隆或下载”,您将看到SSH链接,复制它。
- 在 CMD 运行中
git clone [email protected]:user/my-app.git
(使用您复制的 SSH 链接)
Done
完毕
回答by etc-100g
If I understand the question right, you just want to transfer the history of code from B to C. Actually because git uses de-centric model, B has complete history of the code till the last sync point between B and A.
如果我理解正确,你只是想将代码的历史从 B 转移到 C。实际上因为 git 使用去中心模型,B 拥有完整的代码历史,直到 B 和 A 之间的最后一个同步点。
I can think of three methods if you just want to transfer code history from B to C:
如果你只是想把代码历史从 B 转移到 C,我可以想到三种方法:
- direct copy/rsync/etc. just copy all files and structures in \B-machine\code.git to \C
- git clone: this is best choice if C can access B through http or ssh
- git bundle: git supports bundle command, and after bundle, you copy/rsync/ftp/scp bundle file to C
- 直接复制/rsync/等。只需将 \B-machine\code.git 中的所有文件和结构复制到 \C
- git clone:如果C可以通过http或ssh访问B,这是最好的选择
- git bundle: git支持bundle命令,bundle后,复制/rsync/ftp/scp bundle文件到C