英文:
Git pull response message meaning
问题
-
"From https://github.com/myUserName/myRemote" and "* branch myBranch -> FETCH_HEAD" indicate that Git is providing information about the source and destination of the pull operation. It's showing that it is pulling changes from the specified remote repository (https://github.com/myUserName/myRemote) and updating the local branch named "myBranch" with the changes from the remote branch.
-
Git does not provide this feedback when you do just
git pull
because in that case, Git assumes you are pulling from the default remote and the currently checked-out branch. Therefore, it may consider this information to be redundant or less useful, as it's already implied by the context of the command. However, when you specify a remote and branch in thegit pull myRemote myBranch
command, Git provides more detailed feedback to confirm the source and destination explicitly.
英文:
If I do:
git pull
git responds:
Already up to date.
But if I do:
git pull myRemote myBranch
git responds:
From https://github.com/myUserName/myRemote
* branch myBranch -> FETCH_HEAD
Already up to date.
(According to git branch -vv
myRemote and myBranch are the defaults.)
Questions:
- What does git try to tell me in the part
From https://github.com/myUserName/myRemote
* branch myBranch -> FETCH_HEAD
? - Why does git not give this feedback if I do just
git pull
?
(It looks like git wants to tell me it pulled from myRemote > myBranch but in the case git pull myRemote myBranch
that feedback seems pretty superfluous while in the case git pull
it might actually be useful..)
答案1
得分: 3
首先,这些消息是由Git拉取的“fetch”部分提供的。如果您使用git fetch
,您将获得相同的消息。
当您执行:
git pull myRemote myBranch
… 您实际上并没有将远程的myRemote拉取到本地的myBranch。
myRemote 是远程存储库的名称,myBranch 是您想从远程拉取回来的远程分支的名称。后一个参数实际上是一个refspec,它允许您指定与可选本地同源关联的源(远程)引用。
您还可以使用通配符*
和/或用空格分隔的多个refspecs,从而能够一次性获取多个引用,因此Git为每个引用详细说明了发生的情况。
例如:
git fetch origin master:my_cutty_local_master
… 将获取与origin/master
实际相关的一切,然后在其上创建一个名为my_cutty_local_master
的本地分支。
因此,Git在这里告诉您的是,在服务器上的myBranch
的远程状态(实际上是:myRemote/myBranch
)已被本地获取,然后放在其顶部。实际上不是HEAD
,而是临时存在的FETCH_HEAD
,专门用于此目的。
紧接着,git pull
执行合并过程,如果允许且可能的话,通常会结束为快进更新操作,否则会进行常规合并并解决冲突。
为什么当我只执行
git pull
时,Git不提供这些反馈?
因为在没有参数的情况下执行git pull
时,只能有一个获取的refspec,其中源和目标都是已知的并且是隐式的:您更新当前分支,因此在这里没有额外的精确说明是必要的。
您可能还希望使用git branch -vva
来获取远程分支的名称。
英文:
First of all, these messages are given to you by the "fetch" part of a Git pull. You would get the same if you were using git fetch
.
When you do:
git pull myRemote myBranch
… you don't actually fetch a distant myRemote onto a local myBranch.
myRemote is the name of remote repository and myBranch is the name of the remote branch you want to fetch back from there. The latter parameter is actually a refspec, which allows you to specify a source (distant) reference associated to an optional local homolog.
You may also use a wildcard *
and/or specify multiple refspecs separated by spaces, which enables you to fetch multiple references in one shot, hence the explicit message which tells you exactly what happens for each of them.
For example:
git fetch origin master:my_cutty_local_master
… will fetch everything that actually regards origin/master
, then create a local branch on top of it named my_cutty_local_master
.
So what Git told you here is that the remote state of myBranch
on server myRemote
(that actually is: myRemote/myBranch
) was locally fetched, then HEAD
placed on top of it. Well actually not HEAD
, but FETCH_HEAD
which exists temporary for this sole purpose.
Just after that, git pull
performs a merge process, which usually ends up in a fast forward update operation if allowed and possible, otherwise a regular merge with conflict resolving.
> Why does git not give this feedback if I do just git pull?
Because when doing git pull
without arguments, there can be only one fetched refspec, where both source and destination are known and implicit: you update your current branch, so there's no need for extra precisions here.
You probably also want to use git branch -vva
to get the names of remote branches too.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论