本文介绍了很难理解 git-fetch的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难理解 git-fetch 的细微差别.我知道执行 fetch 会将远程引用提取到本地跟踪分支中.

I am having a hard time understanding the nuances of git-fetch. I understand that doing a fetch, fetches the remote refs into a local tracking branch.

我有几个问题:

  1. 有没有可能不存在本地跟踪分支?如果是这样,它会自动创建吗?

  1. Can it be possible that a local tracking branch does not exist? If so, will it then be created automatically?

如果我执行 fetch 并指定一个非跟踪分支作为目的地会发生什么?

What will happen if I do a fetch and specify a non tracking branch as the destination?

git-fetch 的手册页指定:

The man page for git-fetch specifies:

git-fetch <options> <repository> <refspec>

我将如何使用 refspec 将内容从我的远程主服务器获取到其远程跟踪分支?我相信如果我当前的 HEAD 在 master 上并且我运行,这可能是可能的

How would I use the refspec to fetch contents from my remote master into its remote tracking branch? I believe this may be possible if my current HEAD is on master and I run

git fetch origin master

但是,我可以使用 <+?src:dest> refspec 来实现相同的功能吗?我认为这将有助于我更好地理解这些概念.

However, can I use the <+?src:dest> refspec to achieve the same thing? I think this will help me understand the concepts better.

还有一个问题:

我的 .git/config 文件有以下用于获取的行(仅显示相关行):

My .git/config file has the following line for fetching (showing only relevant lines):

fetch = +refs/heads/*:refs/remotes/origin/*

谁能解释一下这行的确切含义?

Can someone please explain what this line exactly means?

推荐答案

首先,没有本地跟踪分支的概念,只有远程跟踪分支.所以 origin/masterorigin 存储库中 ma​​ster 的远程跟踪分支.

First, there's no such concept of local tracking branches, only remote tracking branches. So origin/master is a remote tracking branch for master in the origin repo.

通常您会执行 git fetch $remote 更新所有远程跟踪分支,并在需要时创建新分支.

Typically you do git fetch $remote which updates all your remote tracking branches, and creates new ones if needed.

然而,您也可以指定一个 refspec,但这不会触及您的远程跟踪分支,相反,它将获取您指定的分支并将其保存在 FETCH_HEAD 上,除非您指定目的地.一般来说,你不想惹这个.

However, you can also specify a refspec, but that will not touch your remote tracking branches, instead, it will fetch the branch you specified and save it on FETCH_HEAD, unless you specify a destination. In general you don't want to mess with this.

最后,

fetch = +refs/heads/*:refs/remotes/origin/*

这意味着如果你这样做

git fetch origin

它实际上会:

git fetch origin +refs/heads/*:refs/remotes/origin/*

这意味着远程 heads/foobar 将是本地 remotes/origin/foobar,加号意味着即使它们不快也会更新-前进.

Which means a remote heads/foobar will be local remotes/origin/foobar, and the plus sign means they'll be updated even if they are not fast-forward.

也许您认为的跟踪分支与 git pull 和合并配置有关.

Perhaps what you think as a tracking branch is something related to git pull and the merge config.

这篇关于很难理解 git-fetch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-12 02:38