我如何存档git分支? [英] How can I archive git branches?

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

问题描述

我的git存储库中有一些旧分支不再处于积极的发展状态。我想归档分支,以便在运行git branch -l -r时不会默认显示。我不想删除它们,因为我想保留历史记录。我怎么能做到这一点?

I have some old branches in my git repository that are no longer under active development. I would like to archive the branches so that they don't show up by default when running git branch -l -r. I don't want to delete them, because I want to keep the history. How can I do this?

我知道可以在refs / heads之外创建ref。例如,refs / archive / old_branch。这样做的后果是什么?

I know that it's possible to create a ref outside of refs/heads. For example, refs/archive/old_branch. Are there any consequences of doing that?

推荐答案

我相信正确的做法是标记分支。如果您在标记分支后删除了分支,那么您已经有效地保留了分支,但它不会混乱分支列表。

I believe the proper way to do this is to tag the branch. If you delete the branch after you have tagged it then you've effectively kept the branch around but it won't clutter your branch list.

如果您需要返回到分支只是检查标签。它将有效地从标签恢复分支。

If you need to go back to the branch just check out the tag. It will effectively restore the branch from the tag.

存档和删除分支:

To archive and delete the branch:

git tag archive/<branchname> <branchname>
git branch -d <branchname>

在一段时间后恢复分支:

To restore the branch some time later:

git checkout -b <branchname> archive/<branchname>

分支的历史记录将保持与您标记历史记录时的完全一样。

The history of the branch will be preserved exactly as it was when you tagged it.

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

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