开发者

How can I fix a local out of date error with git?

I am trying to push to a remote repo but keep getting the error below.

$ git push
To user@remote.net:/home/user/repos/remoterepo.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'user@remote:/home/user/repos/remoterepo.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again开发者_高级运维.  See the
'Note about fast-forwards' section of 'git push --help' for details.

git remote show origin shows master pushes to master (local out of date). I am positive that it shouldn't be out of date as I push only from the branch.

I have 2 questions.

  1. is it possible to force the local branch to overwrite the remote? Pulling will overwrite the changes which are definitely later that the stuff in the repository.

  2. This is about the 2nd or 3rd time I have had this problem. The only thing I can think of that the local version of git is git version 1.7.3.1.msysgit.0 (on Windows)and the remote version is git version 1.6.5 (Ubuntu Jaunty). Is it possible that the different git versions may be causing some corruption?


  1. (see update below) yes, it is possible: git push --force. But do that only if you are absolutely sure that nobody has read the repo since the last push (see How do I push amended commit to the remote Git repository? for an in-deep discussion).
  2. To me, it seems more like you have to git pull first, before you're able to push. I don't think that it is a time related error. The message indicates that there are newer commits on the server (identified by their commit hash, not the commit date)... To see, what's changed, do a git fetch instead of git pull and have a look at the changes using git log origin/master...

Update: in the meanwhile, push learned the --force-with-lease option that ensures that you're not accidently breaking something: https://developer.atlassian.com/blog/2015/04/force-with-lease/. Prefer this over --force whenever possible!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜