Git push 失败 (Git prevents pushing after amending )

当我使用下面命令的时候

git add file
git commit
git push

这时候如果在push之前对刚才的commit做了任何修改(with git commit --amend), 

那么你将会得到如下错误

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.


你可能感兴趣的:(Git push 失败 (Git prevents pushing after amending ))