Git push 失敗 (Git prevents pushing after amending )

當我使用下面命令的時候git

git add file
git commit
git push

這時候若是在push以前對剛纔的commit作了任何修改(with git commit --amend), spa

那麼你將會獲得以下錯誤code

hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

This should only be the case if you're amending an already-pushed commit. Generally you should never do that as you're then modifying published history. In your case however, you should be able to get away with push -f, which will overwrite the remote commit with your amended revision.

一般狀況下,是不該該去修改一個already-pushed commit,但若是你真的遇到這個錯誤,那麼能夠使用 push -f ,覆蓋remote commit.orm

相關文章
相關標籤/搜索