为什么在命令“git fetch uploader master”中包含“master”?

发布于 2024-08-16 23:53:19 字数 400 浏览 5 评论 0原文

help.github 的分叉项目部分拉取上游更改强>它指出:

一段时间过去了,上游存储库已更改,您希望在提交新补丁之前更新您的分支。有两种方法可以做到这一点:

$ git fetch upstream master

$ git merge upstream/master

为什么在 fetch 命令中包含 master ?我查看了 git help fetch 信息,但我不明白包含 master 的作用。谢谢。

In the section Pulling in upstream changes on help.github's Forking a project it states:

Some time has passed, the upstream repo has changed and you want to update your fork before you submit a new patch. There are two ways to do this:

$ git fetch upstream master

$ git merge upstream/master

Why are they including master in the fetch command? I've looked at the git help fetch information but I'm not understanding what including master does. Thanks.

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

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

发布评论

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

评论(1

美人迟暮 2024-08-23 23:53:19

这允许您:

  • 仅更新主上游分支的本地版本(而不是更新上游存储库的所有分支,这可能需要更长的时间)
  • 不立即触发合并(与 pull 命令相反)

git merge 将尝试将上游 master 的本地版本合并到您的 repo master 分支。

所以在这里,对于 fetch 命令来说,master 是一个 refspec。

<refspec>

参数的格式是一个可选的加号 +,后跟源引用 ,后跟冒号 :,后跟目标引用

获取与匹配的远程引用,如果不是空字符串,则快进与其匹配的本地引用使用
如果使用可选的加号 +,则即使不会导致快进更新,也会更新本地引用。

这里, 为空,因此匹配的本地分支(您的主分支)被更新。


没有主人,这将给出:

git fetch upstream 

上述命令从远程 refs/heads/ 命名空间复制所有分支,并将它们存储到本地 refs/remotes/upstream/ 命名空间,除非 branch..fetch 选项用于指定非默认引用规范。

That allows you to:

  • update your local version of the master upstream branch only (as opposed as updating all branches of the upstream repo, which can be longer to do)
  • no trigger a merge right away (as opposed to the pull command)

The git merge will then try to merge that local version of the upstream master to your repo master branch.

So here, master is, for the fetch command, a refspec.

<refspec>

The format of a <refspec> parameter is an optional plus +, followed by the source ref <src>, followed by a colon :, followed by the destination ref <dst>.

The remote ref that matches <src> is fetched, and if <dst> is not empty string, the local ref that matches it is fast-forwarded using <src>.
If the optional plus + is used, the local ref is updated even if it does not result in a fast-forward update.

Here, <dst> is empty, so the matching local branch (your master) is updated.


Without master, that would give:

git fetch upstream 

The above command copies all branches from the remote refs/heads/ namespace and stores them to the local refs/remotes/upstream/ namespace, unless the branch.<name>.fetch option is used to specify a non-default refspec.

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