【问题标题】:Telling from git fetch man page to being able to fetch a single branch从 git fetch 手册页告诉能够获取单个分支
【发布时间】:2017-08-24 01:53:52
【问题描述】:

这是对以下内容的跟进:

How do I fetch only one branch of a remote git repository?

哪些参考:

https://www.kernel.org/pub/software/scm/git/docs/git-fetch.html

这依赖于理解 git fetch 的 refspec 使用模式:

git fetch [<options>] [<repository> [<refspec>…]]

要了解这种使用模式,需要了解“refspec”。例如:

Git - What is "Refspec"

被问到的问题是如何获取(远程存储库的)单个分支,有一个流行的答案:

git fetch <remote_name> <branch_name>

这个答案也很受欢迎:

git remote add -t <remote-branch-name> <remote-name> <remote-url>

我的问题是:如何从 git fetch 和 refspec 文档中找到第一个表单?

我之所以这么问,是因为“git fetch”是一个非常基本的 git 操作,是 git 初学者的入门命令之一,我发现自己无法获得对该命令的充分解释。

【问题讨论】:

  • 请参阅kernel.org/pub/software/scm/git/docs/git-fetch.html 中的“已配置远程跟踪分支”。还有The format of a &lt;refspec&gt; parameter is an optional plus +, followed by the source ref &lt;src&gt;, followed by a colon :, followed by the destination ref &lt;dst&gt;. The colon can be omitted when &lt;dst&gt; is empty.

标签: git branch fetch


【解决方案1】:

如果您要更新当前分支,则命令为

git pull origin master

origin 是远程仓库的名称,master 是要获取并合并到当前分支的分支的名称(假设当前分支是您的本地 @987654324 @)。

对于任何其他分支,命令是

git fetch origin branch:branch

这会从远程分支branch 获取提交,更新本地远程跟踪分支origin/branch 并更新本地分支branch。

【讨论】:

    猜你喜欢
    • 2020-08-17
    • 2022-01-01
    • 2021-03-20
    • 2014-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-24
    • 2011-03-08
    相关资源
    最近更新 更多