简体   繁体   English

如何从Git中的另一台计算机存储库中提取?

[英]How do I pull from another computer's repository in Git?

For example, I have cloned the origin repository on two computers. 例如,我已经在两台计算机上克隆了原始存储库。 Then, I go ahead and make some changes and commit to the local repository of computer A. How do I now pull these changes to computer B? 然后,我继续进行一些更改并提交到计算机A的本地存储库。我现在如何将这些更改提取到计算机B? Both computer A and B are connected to a network. 计算机A和B都连接到网络。

What I am looking for will be the equivalent of someone manually creating a patch and sending it to me, which I can apply to my working copy/local repo. 我正在寻找的将是相当于手动创建补丁并将其发送给我的人,我可以将其应用于我的工作副本/本地回购。

If the machine you want to pull from is accessible via ssh , you can add the repository on it as a remote via ssh, and then pull from it like you would any remote: 如果你想要拉出的机器可以通过ssh访问,你可以通过ssh将其作为远程存储器添加,然后像任何远程一样从中拉出:

$ git remote add repo_b username@host:path/to/repository.git
$ git pull repo_b master

(You can skip the step of adding a remote and just specify the full URL in the git pull command instead of a remote name, but if you're going to be pulling from the repository on a regular basis, adding it as a remote will save you lots of typing.) (您可以跳过添加远程的步骤,只需在git pull命令中指定完整的URL而不是远程名称,但是如果您要定期从存储库中提取,则将其添加为远程名称为您节省大量的打字。)

Have a look at git pull --help 看看git pull --help

This would give something like git pull /my/other/repository 这会产生类似git pull /my/other/repository

You can set up an actual server with git daemon . 您可以使用git守护程序设置实际服务器。 Otherwise, you can use git bundle , which bundles git's internal representation into a file that can be unbundled with git pull at the other end. 否则,您可以使用git bundle ,它将git的内部表示捆绑到一个文件中,该文件可以在另一端使用git pull进行非捆绑。

Eg from the git docs, bundling everything: 例如,从git docs,捆绑所有东西:

git bundle create file.bundle master

Then, on the other end, you can do something like: 然后,在另一端,您可以执行以下操作:

git pull file.bundle HEAD

If you can connect to computer B by ssh, you can use: 如果您可以通过ssh连接到计算机B,则可以使用:

git clone user@host:/path/to/repo

It will enable remote tracking through this ssh connection, and allow you to use git pull/push. 它将通过此​​ssh连接启用远程跟踪,并允许您使用git pull / push。

It worked for me for a local repository with another computer: 它适用于我与另一台计算机的本地存储库:

git remote add origin_username username@10.0.0.2:/home/username/dev/project/main/.git/

git pull origin_username master

or 要么

git pull origin_username some_branch

我想出来了

git clone /path/to/local/repository

A bit too late, but for all it worth and to extend the Antoine Pelisse answer, you can also pull from ssh host that has the same repo with couple of more commits in it, without adding a remote to your config: 有点太晚了,但是为了所有它的价值和扩展Antoine Pelisse的答案,你也可以从具有相同repo的ssh主机中提取几个提交,而无需在配置中添加一个遥控器

git pull user@host:/path/to/repo  # while in the local repo folder

Just to be clear - one of possible uses of this is when you have two hosts (A and B) that cloned the same repo from a remote , and you've committed some changes on host A and do not wish to push them to remote (yet), but instead want to pull those commits from host B. The command above with synchronise your repos without pushing to remote . 需要明确的一点 - 可能的用途之一就是当你有两个主机(A和B)从远程克隆同一个repo时,你已经在主机A上做了一些更改,并且不希望将它们推送到远程 (还),但是想要从主机B中提取这些提交。上面的命令同步你的repos而不推送到远程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM