Git如何改变我已推出的(个人)分支?

g_f*_*red 2 git git-rebase

我读了git的书,但不知何故忘了规则,上面写着:

不要将已推送到公共存储库的提交重新绑定.

如果你遵循这个准则,你会没事的.如果你不这样做,人们会恨你,你会被朋友和家人嘲笑.

在这里,我在工作中创建了一个本地分支功能-xyz,我将其推送到远程仓库.我把它拉到另一台电脑上,做了一些工作并推了推.回到工作岗位上,我拉开了分店.经过几次提交后,我重新设置了我的分支机构.现在我已经完成了feature-xyz,并希望将其推送到远程存储库,但显然失败了以下消息:

$ git push origin feature-xyz
To git@<url>:<repo>.git
 ! [rejected]        feature-xyz -> feature-xyz (non-fast-forward)
error: failed to push some refs to 'git@<url>:<repo>.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Run Code Online (Sandbox Code Playgroud)

显然拉远程分支会产生各种冲突.所以我决定删除远程分支:

git push origin :feature-xyz

并重新创建它:

git push origin feature-xyz

但是我想知道是否有更好的工作流程不涉及删除远程分支?

Von*_*onC 5

不要那么改变.合并.
即,不重订feature-branch之上anotherBranch.合并anotherBranchfeature-branch.

请注意,删除远程分支或push --force同一分支是相同的.
在这两种情况下,您都发布了新的SHA1,重写了历史记录,这对以前拉过的人来说可能不方便feature-branch.