Git在修改提交后阻止推送 [英] Git prevents pushing after amending a commit
问题描述
通常,我只需运行
git添加文件
git commit
git push
但如果我在之前修改提交(使用 git commit --amend
),下一次推送失败并返回
提示:更新被拒绝,因为当前分支的提示位于
提示后面:其远程对象。在再次推送之前,集成远程更改(例如
提示:'git pull ...')。
提示:有关详细信息,请参阅'git push --help'中的'关于快速转发的注意事项'。
如何让git推送更改而不合并分支?我只有一个分支( master
),我是唯一使用这个回购的人,所以为什么这么说?
git branch -a:
* master
remotes / origin / HEAD - >原产地/主人
遥控器/原产地/主人
编辑:使用 gitk HEAD @ {u}
,我看到我有2个分支,一个是原始提交,另一个是修改后的提交。
如果您正在修改已推送的提交,则应该只是这种情况。一般来说,你不应该那样做,因为你正在修改已发布的历史。然而,在你的情况下,你应该能够避开 push -f
,它会用你的修改版本覆盖远程提交。
Usually, I just run
git add file
git commit
git push
but if I amend the commit before pushing it (with git commit --amend
), the next push fails with
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.
How can I let git push the changes without merging branches? I only have one branch (master
) and I'm the only person using this repo so why is it saying this?
git branch -a:
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
EDIT: Using gitk HEAD @{u}
, I see that I have 2 branches, one with the original commit and another with the amended commit.
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.
这篇关于Git在修改提交后阻止推送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!