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关闭分支。删除怎么样?删除分支时,我的历史会发生什么?
3 个解决方案
#1
21
Updated Answer
更新的答案
As @user3159253 stated 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 garbage-收集未通过命名引用(分支,标记等)直接或间接引用的提交。这就是为什么留下对冻结分支的引用很重要的原因。
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>
#2
3
you can refer to git finding unmerged branches to find those branch that have been merged or not.
你可以参考git find unmerged branches找到那些已合并的分支。
If a branch has been merged into other branch, it is safe to delete it use the follwing command.
如果已将分支合并到其他分支中,则可以使用follwing命令将其删除。
git branch -D branch_name
git branch -D branch_name
#3
0
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分支?作为指示。
#1
21
Updated Answer
更新的答案
As @user3159253 stated 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 garbage-收集未通过命名引用(分支,标记等)直接或间接引用的提交。这就是为什么留下对冻结分支的引用很重要的原因。
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>
#2
3
you can refer to git finding unmerged branches to find those branch that have been merged or not.
你可以参考git find unmerged branches找到那些已合并的分支。
If a branch has been merged into other branch, it is safe to delete it use the follwing command.
如果已将分支合并到其他分支中,则可以使用follwing命令将其删除。
git branch -D branch_name
git branch -D branch_name
#3
0
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分支?作为指示。