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

问题描述

我很难理解git-fetch的细微差别。我知道做一个 fetch ,可以将远程引用读取到本地跟踪分支。



我有几个问题不过:


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

  2. 如果我做一个 fetch 会发生什么,以及指定一个非跟踪分支作为目的地?
  3. git-fetch的手册页指定:

      git-fetch< options> <库> <的Refspec> 


我如何使用refspec来获取内容从我的远程主人到其远程追踪分支?我相信这可能是可能的,如果我现在的HEAD是在主,我运行



git fetch origin master



然而,我可以使用< +?src:dest> refspec来达到同样的效果吗?我认为这会帮助我更好地理解这些概念。

还有一个问题:

我的.git /配置文件有以下几行提取(仅显示相关行):

$ $ p $ fc = fetch = + refs / heads / *:refs /遥控器/原产地/ *

有人可以解释这一行究竟意味着什么吗? $ b

解决方案

首先,没有这种本地跟踪分支的概念,只有远程跟踪分支。因此 origin / master origin 回购库中 master 的远程跟踪分支。



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

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



最后,

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

如果你这样做的话

$ g $ f $ g $ g $ f $ g

$ b $ $ $ $
$ b

它实际上会做:

  git fetch origin + refs / heads / *:refs /遥控器/原产地/ * 

这意味着远程 heads / foobar 本地遥控器/原产地/ foobar ,加号表示即使它们不是快进,它们也会更新。 你认为跟踪分支与 git pull 和合并配置有关。


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.

I have a few questions though:

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

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

  3. The man page for git-fetch specifies:

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

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

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

And one more question:

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?

解决方案

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.

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

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.

Finally,

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

That means if you do

git fetch origin

It will actually do:

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

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.

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

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

06-12 02:38