如果我在git中删除父分支,子分支会发生什么 [英] What happens in the child branch if I delete a parent branch in git

查看:682
本文介绍了如果我在git中删除父分支,子分支会发生什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我计划在我的git存储库中重命名一个分支。我发现做这件事的简单方法是从该分支创建一个新的分支并给它所需的名称。

之后,我想删除旧分支(父级)。但是,如果我这样做,恐怕我会在新分支中丢失数据。



如果我删除了那个分支,最初对父分支进行的提交会发生什么?

解决方案

会发生什么?没有任何东西。



如果您创建了另一个分支,您可以删除其他分支而不会丢失任何东西。分支(HEAD)只是一个指向提交的指针。

只要这些提交被分支HEAD(或者是分支HEAD祖先的一部分)引用,它们就不会丢失。 >
即使它们不再被任何分支或标记引用,它们仍然在本地 rel =nofollow> reflog 为(默认情况下)90天。



但是,看手册页为 git branch ,这似乎更简单:

  git分支(-m | -M)[< oldbranch>]< newbranch> 

与:

  -m 
- 移动







  -M 

移动/重命名分支和相应的reflog。 code>




即使新分支名称已存在,也可以移动/重命名分支。



I am planning to rename a branch in my git repository. I found out that the easy way to do that is to make a new branch from that branch and give it the desired name.

After that I want to delete the old branch (the parent). But I'm afraid that I will lose data in my new branch if I do that.

What happens with the commits originally made to the parent branch if I delete that branch?

解决方案

What happens? nothing.

If you create a branch where another is, you can "delete" that other branch without losing anything. A branch (HEAD) is just a pointer to a commit.
As long as those commits are referenced by a branch HEAD (or are part of the branch HEAD ancestors), they aren't lost.
And even if they are no longer referenced by any branch or tag, they are still in the local reflog for (by default) 90 days.

But, looking at the man page for git branch, this seems easier:

 git branch (-m | -M) [<oldbranch>] <newbranch>

With:

-m
--move

Move/rename a branch and the corresponding reflog.

-M

Move/rename a branch even if the new branch name already exists.

这篇关于如果我在git中删除父分支,子分支会发生什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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