为什么git soft delete删除尚未合并的分支?

时间:2018-10-25 21:20:43

标签: git

这是我的理论git分支:

master
feature/something
feature/something-else

如果我当前所在的分支是master,并且feature/something尚未合并到master中,那么git br -d feature/something应该不会成功删除feature/somethingfeature/something尚未合并到master中,并且-d标志应防止feature/something被删除。但是,最近我注意到,此软删除并不能阻止我删除此未合并的分支-feature/something。实际上git br -d feature/something确实会删除feature/something,并且我将从git收到以下警告:

warning: deleting branch 'feature/something' that has been merged to
         'refs/remotes/origin/feature/something', but not yet merged to HEAD.

git未合并到feature/something时,为什么feature/something删除了本地分支机构master的分支-这是我的当前分支?

2 个答案:

答案 0 :(得分:3)

git branch -d的完整文档为:

-d::
--delete::
    Delete a branch. The branch must be fully merged in its
    upstream branch, or in `HEAD` if no upstream was set with
    `--track` or `--set-upstream-to`.

您的警告消息中说,feature/something 配置了上游分支(origin/feature/something),因此配置了HEAD部分(master您的情况)不适用。

此行为自2010年4月15日以来已得到记录(在提交fff0d0abdd中)-因此,它并不是真正的新事物。

答案 1 :(得分:0)

我看到以下错误消息:

  

警告:删除已合并到的分支“功能/内容”            'refs / remotes / origin / feature / something',但尚未合并到HEAD。

因为我是“软”分支,因此删除了git br -d feature/something曾经有一个远程分支origin/feature/something。在上面的question / use case feature/something中已合并到远程主服务器origin/master中,但是我尚未更新master的本地副本。因此,当我尝试以当前分支为git br -d feature/something的方式轻轻地删除master时,我的确成功了,因为远程origin/master副本包含了origin/feature/something的历史记录。

换句话说,此行为仍然可以说是安全的操作-软删除。本地分支将被删除而不会丢失任何工作,但我知道本地master不包括分支feature/something,因此,该消息只是警告。