完整的信息:
error: Ref refs/remotes/origin/user is at 3636498c2ea7735fdcedc9af5ab3c8689e6abe77 but expected a21359c6cc2097c85775cde6a40105f4bd7100ec
From github.com:{github project url}
! a21359c..6273ffc user -> origin/user (unable to update local ref)
同样的情况在这里,但没有关于张贴的评论在我的情况下是正确的,我只有一个分支(master),只使用Unix文件系统,这个错误随机发生时,我运行git fetch -progress -修剪起源和分支是前方或'origin/master'。没有人可以提交,只有1个用户可以推送。
注意:我在acme存储库中有一个子模块,acme有新的子模块更改(新提交),我需要先用git子模块更新做一个子模块更新。
[2014-07-29 13:58:37] Payload POST received from Bitbucket
[2014-07-29 13:58:37] Exec: cd /var/www/html/acme
---------------------
[2014-07-29 13:58:37] Updating Git code for all branches
[2014-07-29 13:58:37] Exec: /usr/bin/git checkout --force master
[2014-07-29 13:58:37] Your branch is ahead of 'origin/master' by 1 commit.
[2014-07-29 13:58:37] (use "git push" to publish your local commits)
[2014-07-29 13:58:37] Command returned some errors:
[2014-07-29 13:58:37] Already on 'master'
---------------------
[2014-07-29 13:58:37] Exec: /usr/bin/git fetch --progress --prune origin
[2014-07-29 13:58:39] Command returned some errors:
[2014-07-29 13:58:39] error: Ref refs/remotes/origin/master is at 8213a9906828322a3428f921381bd87f42ec7e2f but expected c8f9c00551dcd0b9386cd9123607843179981c91
[2014-07-29 13:58:39] From bitbucket.org:acme/acme
[2014-07-29 13:58:39] ! c8f9c00..8213a99 master -> origin/master (unable to update local ref)
---------------------
[2014-07-29 13:58:39] Unable to fetch Git data
要解决这个问题(在我的例子中),如果你的分支在原点之前,只需运行第一个git push。
永久解决
Git update-ref -d解决了这个错误的实例,例如:
git update-ref -d refs/remotes/origin/user
注意,这不会影响远程。
在我的例子中,后续的git获取再次获取该分支,并且后续的git获取/拉不再给出错误“remote ref is at but expected”。
如果这不起作用,临时修复:
还要注意的是,如果你不关心所讨论的分支(例如,你只想更新master,而不是origin/user),一个git pull的变通方法是获取然后合并你所关心的特定分支,例如。
git fetch # may give an error for a particular branch, but other branches will still be successfully fetched
git merge origin/master