组git分支 [英] Group git branches

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

问题描述

我已经接管了一个庞大的git存储库,其中包含许多分支,但似乎没有人真正知道它们的全部含义.有什么方法可以将分支放在某种分组或文件夹中,以便它们仍然存在但不一定列出吗?使重要分支更容易发现.

I've taken over a big git repository with lots of branches that no one really seems to know what they are all about. Is there any way to put branches in some kind of grouping or folder so that they are still there but not necessarily listed? To make the important branches easier to spot.

编辑:我希望能够区分与我一起使用的分支和对我而言没有任何意义但仍然无法删除的分支.

I want to be able to distinguish between the branches that I work with and the branches that don't really make sense to me but still can't be deleted.

推荐答案

删除分支.

如果没有人知道他们是什么,也没有人向他们提出要求,那么任何人都不会.就像ing积旧报纸以防万一一样,它们只是妨碍完成事情.放手吧.尤其是如果它们落后并且很可能是要更新的PITA.

If nobody knows what they are, and nobody has laid claim to them, it's not likely anyone will. Like hoarding old newspapers "just in case", they just get in the way of getting things done. Let it go. Particularly if they're rather behind and likely to be a PITA to update.

删除它们会很快告诉您是否有任何东西依赖于它们.只需极少的可控制的痛苦,您就可以解决很大的不确定性.人们将学会不要将重要的东西留在混乱的地方.

Deleting them will tell you very quickly if anything or anyone was relying on them. For a tiny amount of controllable pain you will have resolved a great uncertainty. And people will learn not to leave important stuff just lying around cluttering everything up.

分支是Git中的临时性事物,很容易以各种方式恢复.您可以通过简单的操作使此过程更轻松,更可靠.这主要是为了使您的开发人员更满意删除分支的想法.

Branches are ephemeral things in Git and easy enough to restore in various ways. There are simple things you can do to make this process easier and more robust. This is mainly to make your devs happier with the idea of deleting branches.

在Git中,标签基本上与分支完全相同,它们只是提交中的标签.不同之处在于它们不动.在分支尖端上做一个标签,然后删除该分支尖端.标记将引用提交并防止其被垃圾回收.

In Git, tags are basically exactly the same as branches, they're just a label on a commit. The difference is they don't move. Make a tag on the branch tip, then delete the branch tip. The tag will reference the commits and keep them from being garbage collected.

git tag <tag> <branch>
git branch -d <branch>

您可以将其与 Maor的答案结合使用,并将标签组织到目录中,例如 archived_branches/.

You can combine this with Maor's answer and organize the tags into a directory like archived_branches/.

如果有人想在该归档分支上工作,则可以从标记创建一个分支并删除该标记.

If somebody wants to work on that archived branch, they can create a branch from the tag and delete the tag.

git checkout -b <tag> <branch>
git tag -d <tag>

这在Git中是非常便宜的过程.

This is an extremely cheap process in Git.

最终,当一段时间内没有人使用这些归档标签时,您可以将它们删除为失效.进行标签归档时,请商定日期.将其标记在共享日历上.

Eventually when nobody's used these archived tags in a while, you can delete them as dead. Agree upon a date when you make the tag archive. Mark it on a shared calendar.

确保检查分支内容是否有任何可挽救的内容.如果有的话,可以将其设为活动分支,或者樱桃选择

Be sure to examine the branch content for anything salvageable. If there is you can make it an active branch, or cherry pick the useful bits.

让希望以防万一"保留旧分支的人来完成这项工作.

Get the people who want to keep old branches around "just in case" to do this work.

您可以检查哪些分支已与主分支 git branch --merged master 合并.删除合并的分支.提交之间的连接将保留分支,合并合并将保留该分支.例如...

You can check what branches have been merged with master git branch --merged master. Delete merged branches. The connections between the commits will retain what was a branch, and the merge commit will retain what that branch was. For example...

A - B - C --------- G - H - I [master]
         \         /
          D - E - F

D-E-F 是分支中的提交,而 G 是合并提交.如果合并提交的操作正确,则该消息将包含有关其工作内容的某种参考.也许是问题跟踪器的链接.有关更多详细信息,请参见我对为什么在合并到母版后为什么删除要素分支? 的答案.

D - E - F are commits in a branch and G is the merge commit. The merge commit's message, if they were doing things right, will contain some sort of reference about what they were working on. Maybe a link to an issue tracker. See my answer to Why should I delete feature branches when merged to master? for more detail.

Git倾向于在垃圾回收之前将旧提交保留大约两周,这样可以给您一些缓冲.您可以在某处记下它们的提交ID,或使用 reflog 恢复它们.恢复它们就像 git branch< name>一样简单.< commit id> .

Git tends to keep old commits around for about two weeks before garbage collecting, so that gives you some buffer. You can note down their commit IDs somewhere, or use the reflog to recover them. Restoring them is as simple as git branch <name> <commit id>.

存储库的备份(您有备份,对吗?)为您提供了另一个缓冲区.

Backups of your repository (you have backups, right?) give you another buffer.

最后,您可以在删除旧分支并将其松散到某个地方之前,对存储库进行克隆.如果发现需要删除旧分支,则可以将其从该存档存储库中拉出.

Finally you can make a clone of the repository just before you delete the old branches and squirrel that away somewhere. If it turns out an old branch needs to be undeleted it can be pulled from that archive repo.

但是可能没有人会再考虑那些旧的分支机构.

But likely nobody will think about those old branches again.

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

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