Git分支删除 [英] Git branch deletion

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

问题描述

在Git中,分支的删除是什么意思?

In Git, what does "deletion" of a branch mean?

它会从存储库中删除吗?或者它仍然可以通过 git branch

Will it be gone from the repository? Or will it still be navigable to via git branch?

导航到我真正想要做的是将分支标记为死路一条,也就是说,这个分​​支离主人太远了,没有人应该用它作为出发点,尽管这个分支有一些好点子,所以我们想保留它,以供参考。

What I really want to do is mark a branch as "dead end", i.e., the branch is so far from master, that nobody should use it as a starting point, though there were some good ideas down that branch, so we'd like to keep it, for reference.

推荐答案

您可以删除分支,但先标记它,以便它的历史不会消失。这样,分支就不会出现在分支列表中,这应该会阻止人们对其进行操作,但是这项工作不会被永久删除(即使在垃圾收集运行之后)。例如,无论何时我有一个不相关的分支,但我不准备永久删除它,我将它标记为archive /< branch-name >。

You can delete the branch, but tag it first, so that it's history doesn't disappear. This way, the branch doesn't show up in the branch list, which should hopefully deter people from working on it, but the work won't be permanently erased (even after garbage collection is run). For instance, whenever I have a branch that has become irrelevant, but I'm not prepared to permanently delete it, I tag it as "archive/<branch-name>".

master 或其他分支上:

While on master or some other branch:

git tag archive/foo foo
git branch -D foo

在删除 foo 之前,它会从 foo 分支中创建一个名为 archive / foo code>。你也可以给标签添加一条消息,它解释了分支中的内容,它为什么存在,为什么现在是死胡同等。

This creates a tag named archive/foo from the foo branch before deleting foo. You can also add a message to the tag, that explains what is in the branch, why it existed, why it's now a dead end, etc.

git tag -m 'Foo is deprecated in favor of bar' archive/foo foo

记录为什么分支被弃用的能力可能是标记与将分支移动到备用名称空间相比的优势。

The ability to record why a branch is being deprecated is perhaps an advantage of tagging versus moving branches to an alternate namespace.

如果您需要重新生成这是简单的:

If you ever need to resurrect a branch that has been archived this way, it's as simple as:

git branch foo archive/foo
git tag -d archive/foo       # Optional

现在分支回来了,好像它从未被删除过。

Now the branch is back as though it was never deleted.

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

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