Does merge direction matter in Mercurial?

六月ゝ 毕业季﹏ 提交于 2019-12-06 17:25:38

问题


Take a simple example: I'm working on the default branch, have some changesets committed locally, and I pulled a few more from the master repository. I've been working for a few days in my isolated local repository, so there's quite a few changes to merge before I can push my results back into master.

default ---o-o-o-o-o-o-o-o-o-o-o  (pulled stuff)
            \
             o----o------------o  (my stuff)

I can do two things now.

Option #1:

hg pull
hg merge

Result #1:

default ---o-o-o-o-o-o-o-o-o-o-o
            \                   \
             o----o------------o-O

Option #2:

hg pull
hg update
hg merge

Result #2:

default ---o-o-o-o-o-o-o-o-o-o-o-O
            \                   /
             o----o------------o

These two results look isomorphic to me, but in practice it seems that option #2 results in way smaller changesets (because it only applies my few changes to the mainline instead of applying all the mainline changes to my few).

My question is: does this matter? Should I care about the direction of my merges? Am I saving space if I do this? (Doing hg log --patch --rev tip after the merge suggests so.)


回答1:


They're (effectively) identical. You see a difference in the hg log --patch --rev X output size because log shows the diff of the result and (arbitrarily) its 'left' parent (officially p1), but that's not how it's stored (Mercurial has a binary diff storage format that isn't patch/diff based) and it's now how it's computed (p1, p2, and most-recent-common-ancestor are all used).

The only real difference is, if you're using named branches, the branch name will be that of the left parent.




回答2:


There is also a difference if you are using Bookmarks. When doing a merge, the branch that you are is the branch that is receiving the changes, so the new changeset will be part of that branch. Supose you have this situation:

default ---o-o-o-o-o-o-o-o-o-o-o   -- Head: Rev 200
            \
             o----o------------o   -- Head: Rev 195, Bookmark: my-stuff

If you merge Rev 200 into Rev 195, the bookmark my-stuff will move on to Rev 201, as you are generating a new changeset in the same branch that has the bookmark.

On the other hand, if you merge 195 into 200, you are generating a changeset in the branch that don't have the bookmark. The my-stuff bookmark will remain in Rev 195.



来源:https://stackoverflow.com/questions/4946930/does-merge-direction-matter-in-mercurial

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!