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.
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.
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 isgit version 1.6.5
(Ubuntu Jaunty). Is it possible that the different git versions may be causing some corruption?
- (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 lastpush
(see How do I push amended commit to the remote Git repository? for an in-deep discussion). - To me, it seems more like you have to
git pull
first, before you're able topush
. 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 agit fetch
instead ofgit pull
and have a look at the changes usinggit 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!
精彩评论