简体   繁体   English

推送被拒绝后的git rebase fixup

[英]git rebase fixup after push is rejected

I have pushed a feature branch to github that I realized I want to rebase in order to squash some commits. 我已经将一个功能分支推送到github,我意识到我想要为了压缩一些提交而重新设置。 I run 我跑

git rebase HEAD~5

on my local branch and set all but the first and last commit to "fixup". 在我的本地分支上设置除了第一个和最后一个提交“fixup”之外的所有提交。 I save and quit and the rebase continues fine. 我保存并退出,并且rebase继续正常。 When I try to push I get 当我试图推动我得到

 error: failed to push some refs to 'git@github.com:username/repo.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.

Is there a way to do this without push -f or is that my only recourse? 有没有办法在没有推-f的情况下做到这一点,还是我唯一的办法? Is there a better way to squash the commits? 是否有更好的方法来压缩提交?

The only way is with git push -f . 唯一的方法是使用git push -f The commits you removed (by replacing them with a single squashed one) are already on the remote. 您删除的提交(通过用一个被压扁的替换它们)已经在遥控器上。 Without -f , you can only add commits, not remove/replace them. 如果没有-f ,则只能添加提交,而不能删除/替换它们。

On the other hand, if nobody has pull ed yet, it shouldn't be a problem. 另一方面,如果还没有人pull ,那应该不是问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM