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

相关文章
相关标签/搜索