Git:如何删除已经提交、推送并合并到master中的分支?

Git:如何删除已经提交、推送并合并到master中的分支?,git,merge,undo,Git,Merge,Undo,我有一个分支已经提交、推送并合并到master中。它没有通过QA。我们需要把那个分支从master中拔出来释放。我怎样才能从主人那里拔出那根树枝。假设分支名称为“待删除”根据 另一方面,如果你真的想摆脱从那以后所做的一切,有两种可能性。第一,如果您尚未发布任何这些提交,只需重置: # This will destroy any local modifications. # Don't do it if you have uncommitted work you want to keep. git

我有一个分支已经提交、推送并合并到master中。它没有通过QA。我们需要把那个分支从master中拔出来释放。我怎样才能从主人那里拔出那根树枝。假设分支名称为“待删除”

根据

另一方面,如果你真的想摆脱从那以后所做的一切,有两种可能性。第一,如果您尚未发布任何这些提交,只需重置:

# This will destroy any local modifications.
# Don't do it if you have uncommitted work you want to keep.
git reset --hard 0d1d7fc32

# Alternatively, if there's work to keep:
git stash
git reset --hard 0d1d7fc32
git stash pop
# This saves the modifications, then reapplies that patch after resetting.
# You could get merge conflicts, if you've modified things which were
# changed since the commit you reset to
另一方面,如果您已经发布了工作,您可能不想重置分支,因为这实际上是在重写历史。在这种情况下,您确实可以恢复提交。对于git,revert有一个非常具体的含义:使用反向补丁创建提交以取消它。这样你就不会重写任何历史

# This will create three separate revert commits:
git revert 0766c053 25eee4ca a867b4af

# It also takes ranges. This will revert the last two commits:
git revert HEAD~2..HEAD

# To get just one, you could use `rebase -i` to squash them afterwards
# Or, you could do it manually (be sure to do this at top level of the repo)
# get your index and work tree into the desired state, without changing HEAD:
git checkout 0d1d7fc32 .
# and then commit
git commit    # be sure and write a good message describing what you just did

你应该有这样的经历:

A--B--C---D--E      <-- Master
 \       /
  Z--Y--X          <-- Your feature
其中
-m
表示提交的父编号

它将在主节点中创建一个新的提交,以撤消功能分支所做的更改。有关更多信息,请访问

git revert -m 1 [sha_of_D]