git --amend --no-edit 被拒绝的推送

4
今天我发现了使用--amend命令时可以结合使用--no-edit参数,但这给我带来了一个问题。以下是具体步骤:
  • git clone
  • did some changes to the code
  • git add .
  • git commit --amend --no-edit
  • git push origin master

    ! [rejected]        master -> master (non-fast-forward)
    error: failed to push some refs to 'https://me@bitbucket.org/myRepo.git'
    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.
    

为什么?

注:我是唯一在该存储库上工作的人。


只是一个愚蠢的问题,你在尝试推送之前有拉取过吗(就像提示所建议的那样)? - Joseph Budin
我刚刚检查过,它不能落后。 - Emaborsa
当你执行git fetch origin命令时,origin/master跟踪分支是否会有任何更新? - Tim Biegeleisen
1
毫无意义,既然我刚刚检出,为什么还要获取? - Emaborsa
显示剩余2条评论
1个回答

10

修改最后一次提交会重写历史记录。如果您确实想这么做,可以使用 git push --force 进行操作。

它告诉您落后的原因是因为本地和远程存在的最后一次提交(也称为“合并基础”)是提示的父级。在这方面上,您落后远程一次提交,远程已经有一个在上述合并基础之上的提交了。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接