git 合并后是否应该删除分支?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10765321/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 13:47:15  来源:igfitidea点击:

Should I delete a branch after merging it?

gitbranching-and-merging

提问by tampe125

After merging a branch, do you delete it from the repository?
However, it's a good practice or not?

合并分支后,是否将其从存储库中删除?
但是,这是一个好习惯吗?

I usually create a lot of branches, since I don't want to break my current release, and I'd wish to delete them to keep things in order.
However, if you work with Assembla or GitHub, your merge requests from old branches will be saved on the site, so if you delete them you'll get an error since it won't be able to fetch them...

我通常会创建很多分支,因为我不想破坏我当前的版本,我希望删除它们以保持秩序。
但是,如果您使用 Assembla 或 GitHub,来自旧分支的合并请求将保存在站点上,因此如果您删除它们,您将收到错误消息,因为它将无法获取它们...

Usually how do manage that?

通常如何管理?

采纳答案by Fred Foo

There's no problem in deleting branches that have been merged in. All the commits are still available in the history, and even in the GitHub interface, they will still show up (see, e.g., this PRwhich refers to a fork that I've deleted after the PR got accepted).

删除已经合并的分支没有问题。所有提交在历史记录中仍然可用,即使在 GitHub 界面中,它们仍然会显示(参见,例如,这个 PR指的是我已经PR 被接受后删除)。

回答by Ashe

I definitely clean up my branches after they've been merged in.

我肯定会在合并后清理我的分支。

We use GitLab and merge requests at work, so the historical information about branches is stored there; I don't need them cluttering my branch list, and when I look at a coworker's fork, ideally I'd like only to see the branches of their current active development. If I'm trying to look at some code on their branch, I want to be able to look through just a few currently active branches, and not every feature or fix they've ever started work on.

我们在工作中使用 GitLab 和合并请求,所以分支的历史信息存储在那里;我不需要它们弄乱我的分支列表,当我查看同事的 fork 时,理想情况下我只想看到他们当前活跃开发的分支。如果我想查看他们分支上的一些代码,我希望能够查看一些当前处于活动状态的分支,而不是他们已经开始工作的每个功能或修复程序。

The above applies to BitBucket and GitHub, too.

以上也适用于 BitBucket 和 GitHub。

The only reason you might have for not deleting a branch post-merge is so you know where a given feature ended, but merge commits (and git merge --no-ffif you really want) make that irrelevant.

您不删除合并后分支的唯一原因是您知道给定功能在哪里结束,但合并提交(git merge --no-ff如果您真的想要)使这无关紧要。

回答by ahmednabil88

Just take care of
All hyperlinks URLs references of your DELETED branches, will be BROKEN.

只需注意
您的 DELETED 分支的所有超链接 URL 引用,将被BROKEN

For example
If you delete branch_feature_xbranch from your repo
The corresponding hyperlink URL of this branch will be broken
https://github.com/username/project/tree/branch_feature_x

例如,
如果你branch_feature_x从你的 repo 中删除分支
,这个分支的相应超链接 URL 将被破坏
https://github.com/username/project/tree/branch_feature_x

回答by AGrigorii

Just to clarify, branch, from git point of view, is just linkonto some commit. By deleting branch, you will not delete commits from git repo. Of course, detachedcommits will be cleaned after some time via git garbage collector.

只是为了澄清,从 git 的角度来看,分支只是链接到一些提交。通过删除分支,您不会从 git repo 中删除提交。当然,分离的提交将在一段时间后通过 git 垃圾收集器清除。

FYI: We're usually merging branches into master via bitbucket interface. There you can set delete feature branch after mergeflag.

仅供参考:我们通常通过 bitbucket 接口将分支合并到 master 中。在那里你可以设置delete feature branch after merge标志。

If you need to deal with too old branches, you could have a look for some utilities, for example this one.

如果您需要处理太旧的分支,您可以查看一些实用程序,例如this