您的位置:首页 > 其它

Git: ! [rejected] master -> master (non-fast-forward)

2014-02-07 07:54 846 查看
  本菜鸟最近开始玩Github了,呵呵,好像还挺有意思的哦。不知道小鸟们,赶紧google去,还有大家赶紧follow我。开个玩笑,进入正体。

         最近想把自己做的一个小小小小的应用放到github上去,顺便学习下git和玩玩github,我用两台电脑往github上的项目push代码,想模拟social coding的感觉。呵呵,但是出现了这个错误:

[html] view
plaincopy

To git@github.com:archermind/LEDTorch.apk-for-Android.git  

 ! [rejected]        master -> master (non-fast-forward)  

error: failed to push some refs to 'git@github.com:archermind/LEDTorch.apk-for-Android.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.  

错误产生的原因是,因为我在A电脑上向github上的项目push过代码,而又在B电脑上修改了代码并且要push到github上去,这个时候,git为了避免冲突的发生,rejected。

        正确的做法是,在push之前git fetch origin,将github上的新代码拉下来,然后在本地merge,如果没有冲突就可以push了,如果有冲突的话要在本地解决冲突后,再push。具体做法就是。

         本菜鸟最近开始玩Github了,呵呵,好像还挺有意思的哦。不知道小鸟们,赶紧google去,还有大家赶紧follow我。开个玩笑,进入正体。

         最近想把自己做的一个小小小小的应用放到github上去,顺便学习下git和玩玩github,我用两台电脑往github上的项目push代码,想模拟social coding的感觉。呵呵,但是出现了这个错误:

[html] view
plaincopy

To git@github.com:archermind/LEDTorch.apk-for-Android.git  

 ! [rejected]        master -> master (non-fast-forward)  

error: failed to push some refs to 'git@github.com:archermind/LEDTorch.apk-for-Android.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.  

错误产生的原因是,因为我在A电脑上向github上的项目push过代码,而又在B电脑上修改了代码并且要push到github上去,这个时候,git为了避免冲突的发生,rejected。

        正确的做法是,在push之前git fetch origin,将github上的新代码拉下来,然后在本地merge,如果没有冲突就可以push了,如果有冲突的话要在本地解决冲突后,再push。具体做法就是。

git fetch origin

git merge origin/master

git push origin master

        

当然在github上玩git的时候,还有一些个小问题,菜鸟们要注意了。

1,git所使用传输的协议通常有三种,HTTP,Git,SSH。但是要注意的是,(HTTP和Git)通常都是只读的,所以虽然二者对大多数人都可用,但执行写操作时还是需要SSH。所以,到github上你可以看到下图:



想要给github上push代码的话,记得要用SSH。具体的做法能就是
git remote add origin [ssh那一栏的地址] //不知道有没有说错哦? 牛牛们,给点意见呗


2,由于大多数Git 服务器使用SSH公钥来授权,所以位了能够向github上的特定项目贡献代码,必须将能够表示自己的publickey提交给github上相关项目的维护人员。他们所要做的事就是把给位贡献者SSH生成的publickey加入进来。如下图:



现在好像更流行的办法是fork该项目吧?没用过,有机会去体验下。

总之,git是个好东西,github也挺好玩的,以后有什么经验再来分享。

转自:http://blog.csdn.net/mci2004/article/details/7763399
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: