我应该在创建新分支之前结帐到 div 吗?

Should I checkout to div before creating a new branch?

据我所知,当我们创建一个新的分支时,它是基于我们创建之前的分支。假设我是 branch-a,我想创建 branch-b。然后,如果我创建 branch-b,然后稍后删除 branch-abranch-b 会怎样?我认为它会失去基础分支 (branch-a)。是真的吗?

branch-a 和在 development 分支创建 branch-b 有什么区别?

… if I create branch-b and then delete branch-a in a later time what will the branch-b? I think it will lose the base branch (branch-a). Is that true?

没有。在 Git 中,分支之间没有关系。分支是一个名称和一个指向提交的指针,仅此而已。 Git 不存储分支的 creation/modification 时间戳、父分支,没有类似的东西。

因此,当基于另一个分支创建分支时,Git 将“父”分支指向的提交复制到新分支。之后与“基础”分支的任何关系都将丢失。

如果您创建 branch-b 然后删除 branch-a 分支 branch-b 没有任何反应。

What is the difference between creating branch-b while being at branch-a and being at development branch?

唯一的区别是复制到分支 branch-b 的提交 ID — 来自分支 branch-adevelopment.

的头提交

PS。顺便说一句,你知道你可以基于任何其他分支、标记或提交 ID 创建分支吗?您没有义务签出分支以从中创建新分支。参见 git help branch<start-point> 可以是任何指向提交的东西。默认值只是 HEAD 即当前提交。示例:

git checkout development
git branch branch-b branch-a # create from the head commit of branch-a
git checkout -b branch-b branch-a # create from branch-a and checkout the new branch

我已经做过很多次了,比如从 develop 分支创建了一个新分支,当遇到一些问题时,我删除了 develop 分支。它对远程没有影响,因为您仅从本地删除分支引用。 因此,即使您在此基础上创建了其他分支,也可以删除该分支。