何时删除Git中的分支? [英] When to delete branches in Git?

查看:156
本文介绍了何时删除Git中的分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们有一个稳定的应用程序。

明天,有人会报告我们决定马上修复的大问题。因此,我们为该修补程序创建了一个关于主的分支,我们将其命名为2011_Hotfix,并且我们将其推送给所有开发人员进行协作修复。



我们修复了这个错误,并将2011_Hotfix合并到master以及当前的开发分支中。并推master。



现在我们如何处理2011_Hotfix?它是否应该永远坐在那里作为一个分支直到时间的尽头,或者我们现在应该删除它,因为它符合它的目的?看起来不清洁的是,将分支留在任何地方,因为分支机构的名单可能会变得很长,其中大部分甚至不再是必要的。



在活动中它应该被删除,它的历史会发生什么?即使实际分支不再可用,这是否会被保留?另外,我将如何移除一个远程分支?

解决方案

您可以通过 git branch -d yourbranch 。如果它包含未合并的更改(即,您将通过删除分支而失去提交),git会告诉您并且不会将其删除。

因此,删除合并的分支很便宜,不会让你失去任何历史。



要删除远程分支,请使用 git push origin:mybranch ,假设您的远程名称是源,并且您想要删除的远程分支名为mybranch。


Suppose we have an application that's stable.

Tomorrow, someone reports a big ol' bug that we decide to hotfix right away. So we create a branch for that hotfix off of "master", we name it "2011_Hotfix", and we push it up so that all of the developers can collaborate on fixing it.

We fix the bug, and merge "2011_Hotfix" into "master" as well as into the current development branch. And push "master."

What do we do with "2011_Hotfix" now? Should it just sit out there as a branch forever until the end of time or should we now delete it, since it has served its purpose? It seems unclean to just leave branches lying around everywhere, as the list of branches will likely become very long, most of which aren't even necessary anymore.

In the event that it should be deleted, what will happen to its history? Will that be maintained, even though the actual branch is no longer available? Also, how would I remove a remote branch?

解决方案

You can safely remove a branch with git branch -d yourbranch. If it contains unmerged changes (ie, you would lose commits by deleting the branch), git will tell you and won't delete it.

So, deleting a merged branch is cheap and won't make you lose any history.

To delete a remote branch, use git push origin :mybranch, assuming your remote name is origin and the remote branch you want do delete is named mybranch.

这篇关于何时删除Git中的分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆