跳到主要內容

發表文章

目前顯示的是 3月, 2020的文章

有時候推不上去… Git push ... fail

偶爾在執行 Push 指令的時候會出現這個錯誤訊息: $ git push To https://github.com/eddiekao/dummy-git.git ! [rejected] master -> master (fetch first) error: failed to push some refs to 'https://github.com/eddiekao/dummy-git.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. 這段訊息的意思是線上版本的內容比你電腦裡這份還要新,所以 Git 不讓你推上去。 怎麼造成的? 通常這個狀況會發生在多人一起開發的時候,想像一下這個情境: Sherly 跟 Eddie 兩個人在差不多的時間都從 Git Server 上拉了一份資料下來準備進行開發。 Sherly 手腳比較快,先完成了,於是先把做好的成果推一份上去。 Eddie 不久後也完成了,但當他要推上去的時候發現推不上去了… 怎麼解決? 解決方法算是有兩招 第一招:先拉再推 因為你電腦裡的內容是比較舊的,所以你應該先拉一份線上版本的回來更新,然後再推一次: $ git pull --rebase remote: Counting objects: 3, done. remote: Compressing objects: 100% (2/2), done. rem