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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4131164/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 09:26:29  来源:igfitidea点击:

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

gitgit-pull

提问by jeffreyveon

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? Both computer A and B are connected to a network.

例如,我在两台计算机上克隆了源存储库。然后,我继续进行一些更改并提交到计算机 A 的本地存储库。我现在如何将这些更改拉到计算机 B?计算机 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.

我正在寻找的将相当于某人手动创建补丁并将其发送给我,我可以将其应用于我的工作副本/本地存储库。

回答by Amber

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 pullcommand 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而不是远程名称,但如果您要定期从存储库中提取,将其添加为远程将节省您打字很多。)

回答by Antoine Pelisse

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

回答by Matthew Flaschen

You can set up an actual server with git daemon. Otherwise, you can use git bundle, which bundles git's internal representation into a file that can be unbundled with git pullat the other end.

您可以使用git daemon设置一个实际的服务器。否则,您可以使用git bundle,它将 git 的内部表示捆绑到一个文件中,该文件可以git pull在另一端解除捆绑。

E.g. 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

回答by Benoit Courtine

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。

回答by McQuade

It worked for me for a local repository with another computer:

它对我来说适用于另一台计算机的本地存储库:

git remote add origin_username [email protected]:/home/username/dev/project/main/.git/

git pull origin_username master

or

或者

git pull origin_username some_branch

回答by Alex

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 remoteto your config:

有点晚了,但是为了扩展 Antoine Pelisse 的答案,您还可以从具有相同存储库的 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 中提取这些提交。 上面的命令同步您的存储库而不推送到remote

回答by Vlad T.

I've come up with

我想出了

git clone /path/to/local/repository