如何在 git 中关闭一个分支

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35738790/
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-09 03:58:26  来源:igfitidea点击:

how to close a branch in git

gitgit-branchgit-taggit-archive

提问by Matthieu

When I know I won't use a branch any more is it possible to close or lock it? Actually I would like to close a branch but I don't think it is possible to close a branch with GIT. what about the delete. What happens to my history when I delete a branch?

当我知道我不再使用分支时,是否可以关闭或锁定它?实际上我想关闭一个分支,但我认为用 GIT 关闭一个分支是不可能的。删除呢。当我删除一个分支时,我的历史记录会发生什么?

回答by Farhad Faghihi

Updated Answer

更新答案

As @user3159253stated in comments of this answer :

正如@user3159253在此答案的评论中所述:

git garbage-collects commits which aren't referenced, directly or indirectly, by a named reference (branch, tag, etc). That is why it is important to leave a reference to a freezed branch.

git垃圾收集未直接或间接被命名引用(分支、标签等)引用的提交。这就是为什么留下对冻结分支的引用很重要的原因。



You can tag the tip of the branch by archiving it, and then delete the branch.

您可以通过归档来标记分支的尖端,然后删除该分支。

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

The branch will be deleted, and can be retrieved later by checking out the tag, and recreating the branch.

分支将被删除,稍后可以通过检出标签并重新创建分支来检索。

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

Or more simply :

或者更简单:

git checkout -b new_branch_name archive/<branchname>

回答by gzh

you can refer to git finding unmerged branchesto find those branch that have been merged or not.

你可以参考git 查找未合并的分支来查找那些已经合并或者没有合并的分支。

If a branch has been merged into other branch, it is safe to delete it use the follwing command.

如果一个分支已经合并到另一个分支中,使用下面的命令删除它是安全的。

git branch -D branch_name

git branch -D branch_name

回答by Thorbj?rn Ravn Andersen

If you want to delete a branch completely, you can just delete it in all your repositories (typically local and remote). git will then clean it up next time it garbage collects.

如果你想完全删除一个分支,你可以在你所有的存储库(通常是本地和远程)中删除它。git 将在下次垃圾收集时将其清理干净。

See How do I delete a Git branch both locally and remotely?for instructions.

请参阅如何在本地和远程删除 Git 分支?为说明。