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

  本菜鳥最近開始玩Github了,呵呵,好像還挺有意思的哦。不知道小鳥們,趕緊google去,還有大家趕緊follow我。開個玩笑,進入正體。

         最近想把自己做的一個小小小小的應用放到github上去,順便學習下git和玩玩github,我用兩臺電腦往github上的項目push代碼,想模擬social coding的感覺。呵呵,但是出現了這個錯誤

[html] view plaincopy
  1. To [email protected]:archermind/LEDTorch.apk-for-Android.git  
  2.  ! [rejected]        master -> master (non-fast-forward)  
  3. error: failed to push some refs to '[email protected]:archermind/LEDTorch.apk-for-Android.git'  
  4. To prevent you from losing history, non-fast-forward updates were rejected  
  5. Merge the remote changes before pushing again.  See the 'Note about  
  6. 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
  1. To [email protected]:archermind/LEDTorch.apk-for-Android.git  
  2.  ! [rejected]        master -> master (non-fast-forward)  
  3. error: failed to push some refs to '[email protected]:archermind/LEDTorch.apk-for-Android.git'  
  4. To prevent you from losing history, non-fast-forward updates were rejected  
  5. Merge the remote changes before pushing again.  See the 'Note about  
  6. 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的時候,還有一些個小問題,菜鳥們要注意了。


1git所使用傳輸的協議通常有三種,HTTPGitSSH。但是要注意的是,(HTTPGit)通常都是隻讀的,所以雖然二者對大多數人都可用,但執行寫操作時還是需要SSH。所以,到github上你可以看到下圖:


想要給githubpush代碼的話,記得要用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


發佈了86 篇原創文章 · 獲贊 18 · 訪問量 24萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章