如何在 Git 中从另一台计算机的存储库中提取内容?
例如,我在两台计算机上克隆了原始存储库。然后,我继续进行一些更改并提交到计算机 A 的本地存储库。现在如何将这些更改拉取到计算机 B?计算机 A 和 B 都连接到网络。
我正在寻找的东西相当于有人手动创建补丁并将其发送给我,我可以将其应用到我的工作副本/本地存储库。
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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
有点太晚了,但尽管如此,为了扩展 Antoine Pelisse 的答案,您还可以从具有相同存储库且有更多提交的 ssh 主机中提取数据,而无需添加远程你的配置:
需要明确的是 - 可能的用途之一是当你有两个主机(A 和 B)从远程克隆相同的存储库,并且你已经在主机上提交了一些更改A 并且不希望将它们推送到远程(尚),而是希望从主机 B 中提取这些提交。上面的命令可以同步您的存储库,而不需要推送到远程 。
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:
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.
它对我来说适用于另一台计算机的本地存储库:
或
It worked for me for a local repository with another computer:
or
我想出了
I've come up with
如果您想要从中提取的计算机可以通过 ssh 访问,您可以通过 ssh 将存储库添加为远程,然后像从任何远程中提取一样:(
您可以跳过此步骤添加远程并只需在 git pull 命令中指定完整的 URL 而不是远程名称,但如果您要定期从存储库中拉取,请将其添加为远程将为您节省大量打字时间。)
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:(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 --help
这会给出类似
git pull /my/other/repository
Have a look at
git pull --help
This would give something like
git pull /my/other/repository
您可以使用 git 守护进程 设置实际的服务器。否则,您可以使用git bundle,它将git的内部表示捆绑到可以通过另一端的 git pull 解绑的文件。
例如,从 git 文档中,捆绑所有内容:
然后,在另一端,您可以执行以下操作:
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 pull
at the other end.E.g. from the git docs, bundling everything:
Then, on the other end, you can do something like:
如果您可以通过 ssh 连接到计算机 B,您可以使用:
它将通过此 ssh 连接启用远程跟踪,并允许您使用 git pull/push。
If you can connect to computer B by ssh, you can use:
It will enable remote tracking through this ssh connection, and allow you to use git pull/push.