只能回购的'混帐状态'说分支在原产地/主人之前。为什么? [英] pull-only repo's 'git status' saying the branch is ahead of origin/master. Why?

查看:75
本文介绍了只能回购的'混帐状态'说分支在原产地/主人之前。为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以情况如下:


$ git status

#分支主文件
#您的分支在[x]提交之前超过'origin / master'。


关于这个问题已经有几个问题了,但似乎没有一个专门针对我的情况。 这个答案其中一个问题来了最近,但没有详细说明。



我只会逐字引用:


如果您在执行git pull remote branch后收到此消息,请尝试使用git fetch进行跟踪。

Fetch似乎正在更新远程分支的本地表示,当你执行git pull remote branch时不一定发生。

该提示确实有效。但不一定发生?为什么不?我需要了解这一点。什么是拉不做?



我不想接管这个问题,所以这是我的详细情况:



涉及三台电脑。在我开发的Mac上,我的家庭服务器,git repo(即origin / master)所在的位置,以及从该服务器拉出的Webfaction帐户。

git push origin master 只能在Mac上使用。作为常规工作流程的一部分,唯一可以在Webfaction上运行的命令是 git pull origin master (作为Fabric部署脚本的一部分)。我不在那里修改代码。我是一个独立的开发人员,所以也没有其他人。



每次我登录Webfaction并检查一些事情,包括 git status 。不可避免地,我总是得到你的分支在前面......的信息。运行 git fetch 会使消息消失。



我即将添加 git抓取到Fabric脚本来解决这个问题,但我想知道为什么需要这样做,特别是在原始/主机的只能拉的克隆上。虽然我每天都使用基本功能,但我对Git并不十分精通,因此我们将赞赏新手友好的解释。

更新 as请求,从 config

  [remoteorigin ] 
fetch = + refs / heads / *:refs / remotes / origin / *
url = git @ [server_address]:[path / to / repo.git]
[branch'master ]
remote = origin
merge = refs / heads / master


解决方案

好吧,从一开始,你就是在做正确的事情。我认为你之前添加的评论是一个很好的解释:


用最简单的术语来说,git pull做了一个git fetch然后是
git merge

这就是我想到的。所以你不必在直线 git pull 之后调用 git fetch - 但是,我几乎可以保证你可以在任何除了 master 分支之外的任何地方使用。



在其中一个链接文章中,删除以下行:

  [remoteorigin] 
fetch = + refs / heads / *:refs / remotes / origin / *< ---删除此

并且它应该解决此问题 - 但是,我无法解释为什么这会起作用。这很难研究,但我认为当你调用 fetch 时,你的git配置实际上指定了要抓取的内容。当你运行 pull 时,我不确定它认为 master 是否同步。



我可以向你保证,如果你是从另一个非主分支那里做的,你就不会看到这个问题。希望其中一位git大师可以详细解释配置中的 fetch 行。

另外,我建议运行下面的命令将设置远程仓库的HEAD,以确保它与本地仓库同步: git push -u origin master






以下是另一个有趣的问题:

很难理解git-fetch




好吧,所以我在我的一个工作流程中测试了这一点,发现了以下内容。



当您执行 git在您的远程服务器上拉出原始主机 .git / 目录中有一个文件引用HEAD所在的位置。两个文件需要注意:

ORIG_HEAD



FETCH_HEAD



您会发现您的 FETCH_HEAD 是正确的,但是 ORIG_HEAD 显示了旧的提交,因此你得到前进x 的原因。当你运行 git fetch 时,你实际上会更正 ORIG_HEAD 中的引用,一切恢复正常。我正在研究如何更改配置中的 fetch 行来解决此问题。


So here's the situation:

$ git status
# On branch master
# Your branch is ahead of 'origin/master' by [x] commits.
#

There are several questions about this on SO already, but none seem to specifically address the type of scenario I have. This answer to one of the questions comes closest, but doesn't go into detail.

I'll just quote it verbatim:

If you get this message after doing a "git pull remote branch", try following it up with a "git fetch".

Fetch seems to update the local representation of the remote branch, which doesn't necessarily happen when you do a "git pull remote branch".

That tip does indeed work. But "doesn't necessarily happen?" Why not? I need to understand this. What is pull not doing?

I don't want to take over that question, so here's my scenario in detail:

Three computers involved. The Mac on which I develop, my home server where the git repo (i.e. origin/master) lives and a Webfaction account that pulls from that server.

I do commits and git push origin master only on the Mac. The only command that ever gets run on Webfaction as part of the normal workflow is git pull origin master (as part of a Fabric deployment script). I don't modify code there. I'm a lone developer, so neither does anyone else.

Every now and then I log in to Webfaction and check on things, including a git status. Inevitably, I always get the "Your branch is ahead..." message. Running git fetch makes the message go away.

I'm about to add git fetch to the Fabric script to be done with this issue, but I want to know why that needs to be done, especially on a pull-only clone of origin/master. I'm not deeply versed in Git though I use the basic functionality daily, so a newbie-friendly explanation would be appreciated.

Update as requested, the relevant bits from config:

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = git@[server_address]:[path/to/repo.git]
[branch "master"]
    remote = origin
    merge = refs/heads/master

解决方案

Ok, so from the outset, you're doing everything correctly. I think the comment you added previously is a pretty good explanation:

In the simplest terms, "git pull" does a "git fetch" followed by a "git merge"

That's how I think of it. So you shouldn't have to call a git fetch after a straight up git pull - but, I can almost guarantee you, this works perfectly fine on anything EXCEPT the master branch.

In one of the linked posts, it said to remove the following line:

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/* <--- Remove this

And it should fix this issue - however, I cannot provide an explanation as to why this works. It's very hard to research, but I think that when you call fetch, your git config actually specifies what exactly to grab. When you're running pull, I'm not sure that it thinks the master is synced.

I can guarantee you that if you did this from another non-master branch, you wouldn't see this problem. Hopefully one of the git gurus can explain the fetch line in config in detail.

Furthermore, I would recommend running the following command instead which sets the HEAD for the remote repository to ensure it is in sync with your local one: git push -u origin master


Here's another interesting question:

Having a hard time understanding git-fetch


Ok, so I tested this on one of my workflows and found the following.

When you execute a git pull origin master on your remote server, there's a file in the .git/ directory that references where your HEAD is at. Two files to take note of:

ORIG_HEAD

FETCH_HEAD

You'll notice that your FETCH_HEAD is correct, but the ORIG_HEAD shows the old commit, hence the reason you're getting the Ahead by x. When you run git fetch, you'll actually correct the reference in ORIG_HEAD and everything is back to normal. I'm looking into how to change the fetch line in the config to fix this behavior.

这篇关于只能回购的'混帐状态'说分支在原产地/主人之前。为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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