可能重复:
'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
gitk --all
以获得您的提交位置的可视化。 - noahgit config branch.master.remote my_git_repo
,它清理了所有问题。 - Garfonzo