在使用git的時候, 我用git commit --amend 命令修改了上一個提交的一些內容, 而上一個提交的內容已經被我用push推到遠程服務器了, 現在我用git push -u origin master 推送 amend之后的提交, 推送失敗了, 並給出了錯誤提示如下:
To https://github.com/Tate-zwt/WTMicroblog.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/Tate-zwt/WTMicroblog.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.
上網搜了一下, 在stackoverflow上找到了解決辦法, 是用 -f 參數 來push: git push -f origin master.stackoverflow真是一個好網站, 就像一個程序員百科全書一樣, 基本上所有的問題都能在上面找到, 你還能貼出你遇到的問題, 讓里面的大神幫忙解決, 解決問題的速度都很快, 起碼我看到的都是半個小時以內就有人回復了, 強烈推薦.
參考: http://stackoverflow.com/questions/3598355/i-am-not-able-to-push-on-git
https://www.kernel.org/pub/software/scm/git/docs/git-push.html#_note_about_fast_forwards