混帐似乎并没有拉出所有更新 - 头部和起源/头部在不同的位置 [英] git doesn't seem to pull all updates - HEAD and origin/HEAD in different positions

查看:96
本文介绍了混帐似乎并没有拉出所有更新 - 头部和起源/头部在不同的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在一个不知如何处理的状态下结束了一个git仓库,并且我需要一些帮助来理解a)发生了什么,存储库如何以及为什么处于这种状态,以及b)我应该对此作出反应。基本上,当从遥控器拉出时,即使我重置了所有更改并再次尝试,我也会在遥控器前面结束。



这就是我所做的:



我分叉了一个git仓库,克隆了上游版本(我没有写入权限),然后将自己的fork添加到远程列表中,这样 git remote -v 显示以下内容:

  $ git remote -v 
mine git@github.com:tlycken / julia.git(fetch)
mine git@github.com:tlycken / julia.git(推送)
origin git://github.com /JuliaLang/julia.git(fetch)
origin git://github.com/JuliaLang/julia.git(push)

我现在想要确保我的本地版本与上游回购中的所有内容保持一致,所以我运行了

  $ git pull origin master 
从git://github.com/JuliaLang/julia
* branch master - > FETCH_HEAD
已经是最新的。
tlycken $ git status
#在分支大师
#你的分支在4次提交之前领先于'origin / master'。
#(使用git push发布你的本地提交)

没有提交,工作目录干净

这使我困惑。为什么我的分支领先于原点大师?我没有改变任何东西。



为了看看我能做些什么,我跑了 git lg (一个用于 git log --graph 的别名,带有一些相关内容)。输出的顶部如下所示:

  * 6912a42  - (HEAD,mine / master,master)合并请求#3052 from daviddelaat / linalgnumber(2013-05-10 11:23:09 -0700)< Viral B. Shah> 
| \
| * 8116d51 - 在一些龙骨操作中使用数字而不是整数(2013-05-10 19:12:45 +0200)< David de Laat>
* | 6cc1532 - 更新手册中的.travis.yml配置。 (2013-05-10 21:41:59 +0530)< Viral B. Shah>
* | fa1e3fe - 更新logdet。关闭#3070。 (2013-05-10 19:35:37 +0530)< Viral B. Shah>
* | a182f7f - (origin / master,origin / HEAD,mine / contrib-base)合并分支'master'of github.com:JuliaLang/julia(2013-05-10 03:10:38 -0400)< Jeff Bezanson>

显然,HEAD的位置不同。为了确保在我开始分支之前在本地存储库中获得正确的代码,我执行了 git reset --hard origin / HEAD 以删除我之前提供的任何内容,并且然后 git pull origin master 以确保我是最新的(即没有重置太远或某物):

  $ git pull origin master 
从git://github.com/JuliaLang/julia
* branch master - > FETCH_HEAD
更新a182f7f..6912a42
快进
base / linalg / dense.jl | 2 + -
base / linalg / factorization.jl | 44 ++++++++++++++++++++++ ----------------------
doc /manual/packages.rst | 3 + -
3个文件已更改,24个插入(+),25个删除( - )
$ git status
#分支主
#分支在原点之前/主'由4提交。
#(使用git push发布你的本地提交)

没有提交,工作目录干净

我回到了我开始的地方。



这是怎么回事?我应该怎么做才能达到我的本地主人从上游获得最新更新的状态? git pull 不会更新您的跟踪参考( origin / ...),以便跟踪各个远程的位置 HEAD s。



运行 git fetch origin ,它会更新所有 origin / ...跟踪参考文献和 git status 将不再认为您处于未来状态。






git pull< remote> < branch> 等价于:


  1. git fetch< remote> < branch> FETCH_HEAD

  2. git merge FETCH_HEAD ol>

    因为它只显式指定了一个要提取的分支,并将其提取到特殊的本地ref FETCH_HEAD 中, t本地更新其他任何内容 - 只有 FETCH_HEAD 以及您正在进入的分支。



    运行 git fetch< remote> 会改变所有与该远程仓库相关的ref。


    I have ended up with a git repository in a state I don't know how to handle, and I need some help with understanding a) what's going on, how and why the repository is in this state, and b) how I should react to it. Basically, when pulling from the remote, I end up ahead of the remote, even if I reset all changes and try again.

    This is what I've done:

    I have forked a git repository, cloned the upstream version (which I don't have write access to) and then added my own fork to the list of remotes, so that git remote -v shows the following:

    $ git remote -v
    mine    git@github.com:tlycken/julia.git (fetch)
    mine    git@github.com:tlycken/julia.git (push)
    origin  git://github.com/JuliaLang/julia.git (fetch)
    origin  git://github.com/JuliaLang/julia.git (push)
    

    I now want to make sure that my local version is up to date with everything in the upstream repo, so I run

    $ git pull origin master
    From git://github.com/JuliaLang/julia
     * branch            master     -> FETCH_HEAD
    Already up-to-date.
    tlycken$ git status
    # On branch master
    # Your branch is ahead of 'origin/master' by 4 commits.
    #   (use "git push" to publish your local commits)
    #
    nothing to commit, working directory clean
    

    This confuses me. Why is my branch ahead of origin master? I haven't changed anything.

    To see if I could do something about it, I ran git lg (an alias for git log --graph with some prettyprint). The top of the output looks like this:

    *   6912a42 - (HEAD, mine/master, master) Merge pull request #3052 from daviddelaat/linalgnumber (2013-05-10 11:23:09 -0700) <Viral B. Shah>
    |\  
    | * 8116d51 - Use Number instead of Integer in some linalg operations (2013-05-10 19:12:45 +0200) <David de Laat>
    * | 6cc1532 - Update .travis.yml configuration in the manual. (2013-05-10 21:41:59 +0530) <Viral B. Shah>
    * | fa1e3fe - Update logdet. Close #3070. (2013-05-10 19:35:37 +0530) <Viral B. Shah>
    * |   a182f7f - (origin/master, origin/HEAD, mine/contrib-base) Merge branch 'master' of github.com:JuliaLang/julia (2013-05-10 03:10:38 -0400) <Jeff Bezanson>
    

    Apparently, the HEAD's are in different positions. To make sure that I get the correct code in my local repository before I start branching out, I did git reset --hard origin/HEAD to remove anything I was ahead, and then git pull origin master to make sure I was up to date (i.e. didn't reset too far or something):

    $ git pull origin master
    From git://github.com/JuliaLang/julia
     * branch            master     -> FETCH_HEAD
    Updating a182f7f..6912a42
    Fast-forward
     base/linalg/dense.jl         |  2 +-
     base/linalg/factorization.jl | 44 ++++++++++++++++++++++----------------------
     doc/manual/packages.rst      |  3 +--
     3 files changed, 24 insertions(+), 25 deletions(-)
    $ git status
    # On branch master
    # Your branch is ahead of 'origin/master' by 4 commits.
    #   (use "git push" to publish your local commits)
    #
    nothing to commit, working directory clean
    

    and I'm back where I started.

    What is going on here? What should I do to get to a state where my local master has the latest updates from upstream?

    解决方案

    git pull doesn't update your tracking refs (origin/...) that keep track of where various remotes' HEADs are.

    Run git fetch origin and it'll update all of the origin/... tracking refs and git status will no longer think you're ahead.


    git pull <remote> <branch> is the equivalent of:

    1. git fetch <remote> <branch>:FETCH_HEAD
    2. git merge FETCH_HEAD

    Because it explicitly specifies only the one branch to fetch, and fetches it into the special local ref FETCH_HEAD, it doesn't update anything else locally - only FETCH_HEAD and the branch you're pulling into.

    Running git fetch <remote> instead will update all of the refs associated with that remote repository.

    这篇关于混帐似乎并没有拉出所有更新 - 头部和起源/头部在不同的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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