What is the difference between merging master into branch and merging branch into master?

后端 未结 1 1928
醉梦人生
醉梦人生 2020-12-13 02:32

I have a branch called master and another called dev. Usually, I do tests and improvements on dev; when done, I merge it into ma

相关标签:
1条回答
  • 2020-12-13 03:00

    TL;DR

    The main difference lies in where the master and dev branches end up pointing. enter image description here

    Full explanation

    Merging one branch into another is not a symmetric operation:

    • merging dev into master, and
    • merging master into dev,

    are, in general, not equivalent. Here is an illustrative example that explains the difference between the two. Let's assume your repo looks as follows:

    enter image description here

    If you merge dev into master

    If master is checked out (git checkout master),

    enter image description here

    and you then merge dev (git merge dev), you will end up in the following situation:

    enter image description here

    The master branch now points to the new merge commit (F), whereas dev still points to the same commit (E) as it did before the merge.

    If you merge master into dev

    If, on the other hand, dev is checked out (git checkout dev),

    enter image description here

    and you then merge master (git merge master), you will end up in the following situation:

    enter image description here

    The dev branch now points to the new merge commit (F', whereas master still points to the same commit as it did before the merge (D).

    Putting it all together

    enter image description here

    0 讨论(0)
提交回复
热议问题