删除" base" Git中的分支

时间:2017-06-29 09:51:05

标签: git git-branch

最初,有分支。

然后,我从创建 feature_1 分支,以实施功能1

在这个新分支上做了一些工作后,我决定实现 feature 2 ,这取决于 feature 1 ,所以我做了:

$ git checkout -b feature_2 feature_1  

我在 feature_2 分支上做了一些工作。

现在,继续开发 feature_1 分支是没有意义的,因为它的所有开发都包含在 feature_2 分支中。

它是否安全"删除 feature_1 分支,即使它是我开始 feature_2 分支的基础? 删除后,我会在Git图表中看到从分支开始的单个 feature_2 分支吗?

我想要实现的是上面所写的内容,一个 feature_2 分支从分支开始,当我开始时 feature_1 分支。最后,将其重命名为 feature_1_2 分支。

1 个答案:

答案 0 :(得分:0)

执行:

# Delete branch feature_1
git branch -d feature_1

# Rename feature_2 -> feature_1_2
git branch -m feature_2 feature_1_2

如果您想确保feature_1上没有其他工作(即提交不在feature_2中),您可以进行快进合并:

git checkout feature_1
git merge --ff-only feature_2

如果合并成功,feature_1feature_2指向同一个提交。因此删除其中一个是安全的。