开发者

Two branch pointers, but merging one

Could someone explain, why in a situation like this:

A--B--C--D  (master)
    \
     \E--F  (feature/xxx, feature/xxx-blah)

if I do a merge feature/xxx-blah into master, the branch pointer 开发者_运维技巧doesn't actually move? The commit is there, master pointer is advanced, but both features point at the same commit F.

I expected to end up with this instead:

A--B--C--D--G  (master, feature/xxx-blah)
    \      /
     \E--F/  (feature/xxx)


This is working as designed - when you merge, you only advance your current branch. This is actually a useful property, since if instead it worked as you expected, you then wouldn't easily be able to tell what was just on your feature branch after you had merged it - master and feature/xxx-blah would contain exactly the same commits.

In most cases ("porcelain" commands in particular), actions in git that create new commits will advance your current branch, but won't advance any other branches as side-effects.

One other point that might be worth making is that you can merge from any commit (or more than one) - they don't have to be branches.


The fact that you comment doing no-ff merges explains why you expected:

A--B--C--D--G  (master, feature/xxx-blah)
    \      /
     \E--F/  (feature/xxx)

But as mentioned in "Why does git use fast-forward merging by default?", no-ff is not the default.
You see a similar scenario in "Moving master head to a branch".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜