git fetch 使用路径而不是远程

发布于 2024-09-25 09:01:40 字数 468 浏览 3 评论 0原文

我理解运行 git fetch的想法,因为远程分支可以通过 git checkout/ 获得。

它会如何工作

git fetch path/to/other/repo

但是,如果我只是运行如何检查相应的分支, ?请注意,该操作会静默运行(即使使用 --verbose),并且不会创建新分支。

编辑:澄清一下:我完全理解 git 如何与遥控器配合使用。我只是对这种替代语法 git fetch path/to/remotegit fetch 感到好奇。它应该如何运作?为什么它不创建新分支?为什么即使在详细模式下它也会安静地运行?预期用途是什么?

I understand the idea of running git fetch <remote>, because the remote branches are then available with git checkout <remote>/<branch>.

But how does it work if I just run

git fetch path/to/other/repo

How can I checkout the corresponding branches? Note that the operation runs silently (even with --verbose), and that no new branch is created.

edit: just to be clear: I perfectly understand how git works with remotes. I'm just curious about this alternate syntax git fetch path/to/remote, or git fetch <url>. How is it supposed to work? Why does it not create new branches? Why does it run silently even in verbose mode? What is the intended usage?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

牛↙奶布丁 2024-10-02 09:01:40

即使就文件系统而言是“本地”的,另一个存储库也是远程存储库。

如果您想使用它,请先将其添加为远程存储库(即使 url 是本地的):

git remote add <name> <url>

然后,按照与远程存储库相同的方式继续执行 git fetch(以及其他命令)机器。

编辑:
如果您从本地路径执行简单的 git fetch 操作,它会创建一个名为 FETCH_HEAD 的新伪分支。您可以在新分支中查看它,例如使用:

git checkout -b new_branch FETCH_HEAD

Even if it's "local" in terms of file system, another repository is a remote repository.

If you want to use it, add it as a remote repository first (even if the url is local):

git remote add <name> <url>

Then, proceed with git fetch (and other commands) in the same way as with repository on remote machines.

EDIT:
If you do a simple git fetch from a local path, it creates a new pseudo-branch called FETCH_HEAD. You can check it out in a new branch for example using:

git checkout -b new_branch FETCH_HEAD
心是晴朗的。 2024-10-02 09:01:40

我认为最好的解释(比文档好得多)是 回答 Jakub Narębski 的另一个问题。

基本上:

git fetch <path>

只是获取远程的 HEAD 分支,并将其本地存储到 FETCH_HEAD 中。

git fetch <path> <branch>

获取远程存储库中的分支并将其存储在 FETCH_HEAD 中。

Jakub Narębski 的回答中描述了更高级的用法,但是,正如他自己所说,最好的获取方法是使用命名遥控器。

I think the best explanation (much better than the docs) is an answer to another question by Jakub Narębski.

Basically:

git fetch <path>

just fetches the HEAD branch of the remote, and stores it locally into FETCH_HEAD.

git fetch <path> <branch>

fetches the branch in the remote repo and stores it in FETCH_HEAD.

More advanced usages are described in Jakub Narębski's answer, but, as he states himself, the best way to fetch is to use named remotes.

疯了 2024-10-02 09:01:40

您必须显式地将 refspec 传递给 git fetch 才能获取远程分支。 git help fetch 应该有帮助。

You have to explicitly pass a refspec to git fetch to get the remote branches. git help fetch should help.

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