git 知道合并后哪个分支是哪个分支吗?
抱歉,如果这是一个只有是/否答案的愚蠢问题,但如果我理解正确的话,在 git 中,分支只是指向提交的指针。这是否意味着一旦合并两个分支,git 就不知道哪个分支指向哪一组提交?
之前
A---B---C---D---E <- X
\
1----2----3----4 <- Y
之后
A---B---C---D---E--M <-X & Y
\ /
1----2----3----4
Sorry if this is a stupid question with just a yes/no answer, but if I understand correctly, in git a branch is just a pointer to a commit. Doesn't this imply that once you've merged two branches, git doesn't know which one pointed to which set of commits?
Before
A---B---C---D---E <- X
\
1----2----3----4 <- Y
After
A---B---C---D---E--M <-X & Y
\ /
1----2----3----4
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果我没记错的话,您将一个分支合并到另一个分支中,就像 feature1 合并到 master 中一样,所以 master 现在指向合并提交,但 feature1 仍然指向它之前指向的位置。
Jefromi 编辑:这是正确的。图片应该是这样的:
If I recall correctly you merge a branch into another one, like feature1 into master, so master now points to merge-commit but feature1 still points to where it pointed before.
Edit by Jefromi: This is correct. The pictures should look like this:
合并分支实际上并不合并另一个分支的引用;它将另一个分支的内容合并到当前分支中。
Merging branches doesn't actually merge the ref of the other branch; it merges the content of the other branch into the current one.
Chris Johnson 的评论当然是正确的,git 不记录分支名称。但其他答案向我表明,可能不清楚这种情况是如何发生的。下面是一个示例:
假设工作是在
main
和feature1
分支上并行完成的。现在您希望将您的
featrue1
分支与main
同步,以便有权合并到main
的开发人员可以通过快进合并来完成此操作。您可以这样做:现在存储库的维护者可以通过快进合并到
main
:此时您无法再看到哪个分支
M2
或>F1
属于。诀窍是维护者在合并到
main
时在这种情况下使用--no-ff
选项。使用此选项,我们会看到下图:Chris Johnson is of course correct in his comment, git does not record the branch name. But the other answers suggest to me, that it may be unclear how this situation may arise. Here is an example:
Lets assume work is done on
main
and afeature1
branch in parallel.Now you want to sync your
featrue1
branch withmain
so that the developer with the permission to merge tomain
can do so via fast forward merge. You could do it like this:Now the maintainer of the repo can merge to
main
via fast forward:At this point you cannot see any more to which branch
M2
orF1
belong.The trick is for the maintainer to use the
--no-ff
option in this case when merging tomain
. With this option we would have seen the following graph: