Git上传失败

当你推送到远端分支时会碰到的主要问题是,其他人在此期间也推送了的情况。 如果你和另一个开发者同时克隆了,又都有提交,那么当她推送后你也想推送时,默认情况下 Git 不会让你覆盖她的改动。 相反的,它会在你试图推送的分支上执行 git log,确定它能够在你的推送分支的历史记录中看到服务器分支的当前进度。 如果它在在你的历史记录中看不到,它就会下结论说你过时了,并打回你的推送。 你需要正式提取、合并,然后再次推送 —— 以确定你把她的改动也考虑在内了。

当你试图推送到某个以被更新的远端分支时,会出现下面这种情况:

$ git push github master
To git@github.com:schacon/hw.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:schacon/hw.git'
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.

你可以修正这个问题。执行 git fetch github; git merge github/master,然后再推送

参考: http://gitref.cyj.me/zh/remotes/

posted @ 2013-05-07 09:55  Iwillbback  阅读(268)  评论(0)    收藏  举报