Git Pull不会执行Git获取 [英] Git Pull Doesn't Do A Git Fetch

查看:175
本文介绍了Git Pull不会执行Git获取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的理解一直是 git pull 基本上是 git fetch git merge ... 但我遇到过很多次拉动,然后比较显示不是我的变化,直到我也做了一个抓取:



(在分支blob上):

  git pull原点blob 
git diff原点/ blob< ; - 显示了一堆不是我的变化,而是从其他人那里得到的变化
git fetch
git diff origin / blob< - 显示我的更改

我的理解是否拉错?

解决方案

<这是一个常见的混淆之处,因此 #git IRC频道有一个固定帮助文本,名为!pull4


我们建议不要使用'git fetch / pull < refspec>'分支参数),因为它不更新< remo te> /< branch> ref。正确获取东西的简单方法是获取所有东西:如果您有一个远程控制器,那么'git fetch'或'git pull'就足够了;否则我们推荐'git fetch '(加上'git merge /< branch>',如果你想要拉/合并)。

这里发生的事情是: git pull 没有参数, 默认远程(通常 origin ),然后 git merge s对应于当前本地分支的远程分支。 git pull< remote> 对明确指定的远程进行同样的操作。然而,四字拉, git pull< remote> < branch> ,将该分支提取到临时位置, FETCH_HEAD 没有更新您的跟踪分支,然后将 FETCH_HEAD 合并到您当前的分支中。

因此,通过使用 git pull origin blob ,你说我想合并最近版本的 blob 分支到远程的 origin c>到我当前的分支,而不更新任何我的跟踪分支或获取任何其他数据。



如果你的分支合并配置是正确的 git clone git checkout 尝试自动设置它们),您可以将 git pull git pull origin ,它将获取所有内容,然后合并与当前签出的分支相对应的分支。如果你想更明确地控制,使用 git fetch ,然后使用 git merge git pull< remote> < branch> 很少是你想要的。



git fetch
修正你的例子中的事情是,在拉动之后,你的本地分支已经用最新的远程提交进行了更新,但是跟踪分支没有被更新。 git fetch 更新追踪分支与那些提交,在这一点上差异开始再次感觉。)

My understanding has always been that git pull is essentially a combination of git fetch and git merge ... but I have encountered it a number of times where pulling, then comparing shows changes that aren't mine until I also do a fetch:

(on branch blob):

git pull origin blob
git diff origin/blob  <- shows a bunch of changes that aren't from my but were just pulled from others
git fetch
git diff origin/blob  <- shows just my changes

Is my understanding of pull incorrect?

解决方案

This is a common source of confusion, so much so that the #git IRC channel has a canned help text for it, called !pull4:

We recommend against using 'git fetch/pull <remote> <refspec>' (i.e. with branch argument), because it doesn't update the <remote>/<branch> ref. The easy way to fetch things properly is to get everything: 'git fetch' or 'git pull' are sufficient if you have one remote; otherwise we recommend 'git fetch <remote>' (plus 'git merge <remote>/<branch>' if you wanted to pull/merge).

What's happening here is that git pull with no arguments does a git fetch on the "default remote" (typically origin), then git merges the remote branch corresponding to your current local branch. git pull <remote> does the same thing with an explicitly specified remote. However, the "four-word pull", git pull <remote> <branch>, fetches that branch into a temporary location, FETCH_HEAD, without updating your tracking branches, and then merges FETCH_HEAD into your current branch.

So, by using git pull origin blob, you are saying "I want to merge the latest version of the blob branch on the remote origin into my current branch, without updating any of my tracking branches or fetching any other data".

If your branch merge configurations are correct (and they probably are, since git clone and git checkout try to set them up automatically), you can just git pull or git pull origin and it'll fetch everything and then merge the branch corresponding to your currently-checked-out branch. If you want more explicit control, use git fetch and then git merge. git pull <remote> <branch> is rarely what you want.

(The reason the git fetch fixes things in your example is that, after the pull, your local branch has been updated with the latest remote commits, but the tracking branch hasn't been. git fetch updates the tracking branch with those commits, at which point the diffs start making sense again.)

这篇关于Git Pull不会执行Git获取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆