Git - “你的分支比'origin/master'超前了3次提交。”

13

可能重复:
'git pull origin mybranch'将本地mybranch与远程版本相比,落后N个提交。为什么?

我在git中得到了这些信息。

>git status
# On branch master
# Your branch is ahead of 'origin/master' by 3 commits.
#
nothing to commit (working directory clean)

而且,当我尝试推送时,我得到了这个错误:

fatal: failed to write object
error: unpack failed: unpacker exited with error code
To ssh:<my repository>
 ! [remote rejected] master -> master (n/a (unpacker error))
error: failed to push some refs to 'ssh:<my repository>'

我已经通过谷歌搜索了一下(例如,这里有一个关于此问题的stackoverflow问题 - 'git pull origin mybranch' leaves local mybranch N commits ahead of origin. Why?),通常建议是先拉取再推送。但对我来说这不起作用 - 拉取告诉我我已经是最新的了。我也尝试了 'git fetch origin' (没有变化)。我还尝试过:

> git remote show origin
* remote origin
  URL: ssh://<my repository>
  HEAD branch: master
  Remote branch:
    master tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (fast forwardable)

如果有帮助的话。

我还尝试在我们的Web服务器上添加一个虚拟文件(也检出了主分支),提交并推送它,然后在本地拉取下来。这一切都很顺利。但我仍然无法推送。有人能告诉我该怎么解决吗?我甚至不知道相对于存储库快进是什么意思。

谢谢,Max

编辑-针对ebneter和dan(谢谢)

> git config -l
user.name=Max Williams
push.default=tracking
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
remote.origin.url=ssh://<my repo url>
branch.master.remote=origin
branch.master.merge=refs/heads/master

http://dl.dropbox.com/u/846812/gitk.png可以看到gitk的屏幕截图。

  • 我对Git还不太熟悉,无法很好地解释这个问题,但我想知道在顶部区域第6行作为root用户提交的“merge branch master…”是否可能搞砸了事情。我不记得我以root身份提交过,感到困惑。

Dan - 我想你是对的:当我尝试推送时遇到的错误是:

error: unable to create temporary sha1 filename ./objects/05: File exists

fatal: failed to write object
error: unpack failed: unpacker exited with error code

编辑 - 我之前提到的另一个stackoverflow问题中的这个评论确实解决了它:

仅使用git remote(显示GitHub存储库的正确地址)是不够的。为了避免在git pull之后出现“您的分支超前”的警告消息,您需要首先为分支定义远程名称。因此,我的建议是:键入 git config branch.master.remote yourGitHubRepo.git,然后尝试 git pull 和 git status,看看问题是否仍然存在。- VonC 11月16日20:22


2
尝试运行 gitk --all 以获得您的提交位置的可视化。 - noah
你所遇到的错误通常表示远程出现了问题。但是,你似乎在暗示你可以从 Web 服务器推送。是这样吗?你能展示一下你的配置文件的全部内容吗(git config -l)? - ebneter
这里提供了一个答案:[https://dev59.com/N3I-5IYBdhLWcg3wqqTg] - Surya
感谢让我再次查看这个问题,Surya。我在帖子中说过我已经阅读了那个页面,但我没有仔细阅读,因为这个建议解决了它:<br/>仅使用git remote(显示GitHub存储库的正确地址)是不够的。为了避免在git pull后出现“您的分支领先”的警告消息,您需要首先为分支定义远程名称。因此,我的建议是:键入git config branch.master.remote yourGitHubRepo.git,然后尝试git pull和git status,看看问题是否仍然存在。 - Max Williams
虽然这是一个旧帖子,但我想说一下,在另一个帖子中提到的评论对我也起了作用。我执行了 git config branch.master.remote my_git_repo,它清理了所有问题。 - Garfonzo
1个回答

8

看起来你遇到的问题与“拆包错误”有关,这在“远程拒绝”行中提到。由于某些原因,远程端无法解包发送给它的对象。这可能是由许多原因引起的。你可以尝试以下一些方法:

git fsck --full

请在本地和远程(如有可能)都运行此程序。

git repack remotes/origin/master

在本地仓库上运行此命令。

如果以上方法都无法解决问题,请尝试通过谷歌搜索git "unpacker error"获取其他想法。我个人从未遇到过这个问题,所以这大概就是我能给出的全部建议了。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接