git can merge and fetch but not push and pull

时间:2016-07-11 19:46:54

标签: git merge push branch commit

I know this type of question has been asked everywhere, but none of the answers I find have helped. Typical problem:

[me@my_server]$ git merge origin development
Already up-to-date. Yeeah!
[me@my_server]$ git push origin development
To ssh://git@git.work.com:8022/my_project
 ! [rejected]        development -> development (non-fast-forward)
error: failed to push some refs to 'ssh://git@git.work.com:8022/my_url'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again.  See the 'Note about
fast-forwards' section of 'git push --help' for details.

What the push error is saying to me is that something is out of sync. That if my push were to be accepted, somewhere along the commit chain, the history of some commit will be lost. Instead of committing each change to the remote development branch in a linear fashion, accepting my push will force a non-linear change to occur.

The solution to that is to merge whatever is going on in development to my local branch, right? ...but my branch is already completely up-to-date with development. So if the 2 branches match except for my one change I'm trying to push (I just made a new file), then why is it rejecting? Where is this out-of-line non-fast-foward commit ?? Is there some log I can check to find the problem child and destroy it?

thanks

1 个答案:

答案 0 :(得分:1)

You tried to push development without checking the state of origin/development, which you are probably out of sync with (hence the rejection). You probably want to git pull origin development (which will fetch the changes on origin/development and merge your stuff into that) and then git push origin development (which will push your new changes, merged on top of the latest stuff from origin, up to the server such that its fast forward-able merge able up there). You can also do a git pull --rebase if you want to do it that way instead of a merge.