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

发布于 2024-10-01 19:14:49 字数 148 浏览 0 评论 0原文

例如,我在两台计算机上克隆了原始存储库。然后,我继续进行一些更改并提交到计算机 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

芸娘子的小脾气 2024-10-08 19:14:50

有点太晚了,但尽管如此,为了扩展 Antoine Pelisse 的答案,您还可以从具有相同存储库且有更多提交的 ssh 主机中提取数据,而无需添加远程你的配置:

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

需要明确的是 - 可能的用途之一是当你有两个主机(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:

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.

青瓷清茶倾城歌 2024-10-08 19:14:50

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

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

git pull origin_username master

git pull origin_username some_branch

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
负佳期 2024-10-08 19:14:50

我想出了

git clone /path/to/local/repository

I've come up with

git clone /path/to/local/repository
七颜 2024-10-08 19:14:49

如果您想要从中提取的计算机可以通过 ssh 访问,您可以通过 ssh 将存储库添加为远程,然后像从任何远程中提取一样:(

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

您可以跳过此步骤添加远程并只需在 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:

$ 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.)

故人的歌 2024-10-08 19:14:49

看看 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

辞取 2024-10-08 19:14:49

您可以使用 git 守护进程 设置实际的服务器。否则,您可以使用git bundle,它将git的内部表示捆绑到可以通过另一端的 git pull 解绑的文件。

例如,从 git 文档中,捆绑所有内容:

git bundle create file.bundle master

然后,在另一端,您可以执行以下操作:

git pull file.bundle HEAD

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:

git bundle create file.bundle master

Then, on the other end, you can do something like:

git pull file.bundle HEAD
↙温凉少女 2024-10-08 19:14:49

如果您可以通过 ssh 连接到计算机 B,您可以使用:

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

它将通过此​​ ssh 连接启用远程跟踪,并允许您使用 git pull/push。

If you can connect to computer B by ssh, you can use:

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

It will enable remote tracking through this ssh connection, and allow you to use git pull/push.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文