对于使用git的人来说,重新发布是一项频繁的任务。 我们有时会使用rebasing从最后的修改中分支我们的代码,甚至只是从一个分支中删除提交。
很多时候,当你试图在重新发布后推送时,你会看到类似下面的情况:
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.
通常情况下,开发者在推送过程中会使用 `` --force ```push 或-f` 标志来强制推送代码修改:
git push origin my-branch --force
# or
git push origin my-branch -f
最近我惊讶地发现,你也可以在分支名称前加上+ 来强制推送:
git push origin +my-branch
+ 语法很有趣,但似乎并不直观,所以我不会使用这种做法,但这并不意味着你不应该这样做