理解 git commit with amend option

Understanding git commit with amend option

假设我有一个文件'A' 我已经修改了文件并通过以下命令将其推送到存储库

git add A
git commit -m "changed A"
git push 

后来我意识到我需要更改文件 'B' 所以我修改了它并 运行 按照命令

    git add B
    git commit --amend -m "changed AandB"
    git push

但我收到错误..

error: failed to push some refs to 'https://xxx@github.com/xx/xx'
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.

我应该怎么做才能克服这个错误

Amend 实际上改变了 git 历史。您需要执行强制 (-f) 推送以更新遥控器。

N.B: 强制推送会将远程的历史记录替换为本地的历史记录,因此危险.

$ git push -f