git fetch 使用路径而不是远程
我理解运行 git fetchgit checkout
获得。
它会如何工作
git fetch path/to/other/repo
但是,如果我只是运行如何检查相应的分支, ?请注意,该操作会静默运行(即使使用 --verbose
),并且不会创建新分支。
编辑:澄清一下:我完全理解 git 如何与遥控器配合使用。我只是对这种替代语法 git fetch path/to/remote
或 git 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
即使就文件系统而言是“本地”的,另一个存储库也是远程存储库。
如果您想使用它,请先将其添加为远程存储库(即使 url 是本地的):
然后,按照与远程存储库相同的方式继续执行 git fetch(以及其他命令)机器。
编辑:
如果您从本地路径执行简单的 git fetch 操作,它会创建一个名为 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):
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 calledFETCH_HEAD
. You can check it out in a new branch for example using:我认为最好的解释(比文档好得多)是 回答 Jakub Narębski 的另一个问题。
基本上:
只是获取远程的
HEAD
分支,并将其本地存储到FETCH_HEAD
中。获取远程存储库中的分支并将其存储在 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:
just fetches the
HEAD
branch of the remote, and stores it locally intoFETCH_HEAD
.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.
您必须显式地将
refspec
传递给git fetch
才能获取远程分支。git help fetch
应该有帮助。You have to explicitly pass a
refspec
togit fetch
to get the remote branches.git help fetch
should help.