threads / discuss / 28344

merge result

Subject: merge result

## tl;dr

6 messages between Sep 9, 2011 and Sep 10, 2011.

replies: 5people: 3as markdown or json

Lynn Lin· Sep 9, 2011, 10:54 UTC · lore
Hi All,
   When I merge branch A back to master branch,if there are same
commit(developer do double commit) both in master and A branch, there
will be two same commit in master branch.For example
   1->2->3-4>5        Master
       |
       4->6->7          A

When I merge A branch into master,the two same 4 commit will present in master branch.

Is there any wrong with my operation?

Thanks for your help Lynn

Andrew Ardill· Sep 9, 2011, 12:41 UTC · re: Lynn Lin · lore

Re: merge result

Hi Lynn,

If you merge two branches together you are merging the state of the head of those trees, not re-applying commits on top of each other. The changes introduced in commit 4 will therefore not be applied twice, but will more-or-less be ignored.

Perhaps you are not trying a merge operation, but something else? Is this issue hypothetical, or is it something you have experienced??

Regards,
Andrew Ardill
On 9 September 2011 20:54, Lynn Lin <lynn.xin.lin@gmail.com> wrote:
Show 22 quoted lines
> Hi All,
>   When I merge branch A back to master branch,if there are same
> commit(developer do double commit) both in master and A branch, there
> will be two same commit in master branch.For example
>
>
>   1->2->3-4>5        Master
>       |
>       4->6->7          A
>
> When I merge A branch into master,the two same 4 commit will present
> in master branch.
>
> Is there any wrong with my operation?
>
> Thanks for your help
> Lynn
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
Lynn Lin· Sep 10, 2011, 01:07 UTC · re: Andrew Ardill · lore

Re: merge result

On Fri, Sep 9, 2011 at 8:41 PM, Andrew Ardill <andrew.ardill@gmail.com> wrote:
Show 9 quoted lines
> Hi Lynn,
>
> If you merge two branches together you are merging the state of the
> head of those trees, not re-applying commits on top of each other. The
> changes introduced in commit 4 will therefore not be applied twice,
> but will more-or-less be ignored.
>
> Perhaps you are not trying a merge operation, but something else? Is
> this issue hypothetical, or is it something you have experienced??

1$ git checkout master 2$ git edit and commit 3$ git checkout branchA 4$ git edit and commit 5$ git checkout master 6 $ git merge branchA

2 and 4 change is the same
Show 30 quoted lines
> Regards,
>
> Andrew Ardill
>
>
>
> On 9 September 2011 20:54, Lynn Lin <lynn.xin.lin@gmail.com> wrote:
>> Hi All,
>>   When I merge branch A back to master branch,if there are same
>> commit(developer do double commit) both in master and A branch, there
>> will be two same commit in master branch.For example
>>
>>
>>   1->2->3-4>5        Master
>>       |
>>       4->6->7          A
>>
>> When I merge A branch into master,the two same 4 commit will present
>> in master branch.
>>
>> Is there any wrong with my operation?
>>
>> Thanks for your help
>> Lynn
>> --
>> To unsubscribe from this list: send the line "unsubscribe git" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>
>
Matthieu Moy· Sep 9, 2011, 13:00 UTC · re: Lynn Lin · lore

Re: merge result

Lynn Lin <lynn.xin.lin@gmail.com> writes:
> Hi All,
>    When I merge branch A back to master branch,if there are same
> commit(developer do double commit) both in master and A branch, there
> will be two same commit in master branch.

They cannot be the "same" commit. They are different commits (i.e. different sha1 identifier, and probably different trees), even though they may have the same commit message and represent the same diff.

>    1->2->3-4>5        Master
>        |
>        4->6->7          A
A more accurate drawing would be
    1->2->3-4>5        Master
        |
        4'->6->7          A
and after merging, you'd get
    1->2->3-4>5-->8  A, master
        |       /
        4'->6->7

with 8 having both 4 and 4' as ancestors. There's nothing wrong with it. Git cannot remove either 4 or 4' without rewritting history, and "git merge" does not rewrite history.

If you really really want to avoid this duplication in the history, then learn about rebase (which is both powerfull and dangerous, you've been warned).

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Lynn Lin· Sep 10, 2011, 01:11 UTC · re: Matthieu Moy · lore

Re: merge result

On Fri, Sep 9, 2011 at 9:00 PM, Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> wrote:

Show 30 quoted lines
> Lynn Lin <lynn.xin.lin@gmail.com> writes:
>
>> Hi All,
>>    When I merge branch A back to master branch,if there are same
>> commit(developer do double commit) both in master and A branch, there
>> will be two same commit in master branch.
>
> They cannot be the "same" commit. They are different commits (i.e.
> different sha1 identifier, and probably different trees), even though
> they may have the same commit message and represent the same diff.
>
>>    1->2->3-4>5        Master
>>        |
>>        4->6->7          A
>
> A more accurate drawing would be
>
>    1->2->3-4>5        Master
>        |
>        4'->6->7          A
>
> and after merging, you'd get
>
>    1->2->3-4>5-->8  A, master
>        |       /
>        4'->6->7
>
> with 8 having both 4 and 4' as ancestors. There's nothing wrong with it.
> Git cannot remove either 4 or 4' without rewritting history, and "git
> merge" does not rewrite history.
so confused here.If 4' is just next 4 commit,how can the diff work? for example
1->2->4->4'->6->...
 diff 4 and 4' is a little confused,correct?
Thanks for your time to explain here and teach me
Show 8 quoted lines
> If you really really want to avoid this duplication in the history, then
> learn about rebase (which is both powerfull and dangerous, you've been
> warned).
>
> --
> Matthieu Moy
> http://www-verimag.imag.fr/~moy/
>
Matthieu Moy· Sep 10, 2011, 11:35 UTC · re: Lynn Lin · lore

Re: merge result

Lynn Lin <lynn.xin.lin@gmail.com> writes:
Show 24 quoted lines
>>>    1->2->3-4>5        Master
>>>        |
>>>        4->6->7          A
>>
>> A more accurate drawing would be
>>
>>    1->2->3-4>5        Master
>>        |
>>        4'->6->7          A
>>
>> and after merging, you'd get
>>
>>    1->2->3-4>5-->8  A, master
>>        |       /
>>        4'->6->7
>>
>> with 8 having both 4 and 4' as ancestors. There's nothing wrong with it.
>> Git cannot remove either 4 or 4' without rewritting history, and "git
>> merge" does not rewrite history.
> so confused here.If 4' is just next 4 commit,how can the diff work? for example
>
> 1->2->4->4'->6->...
>
>  diff 4 and 4' is a little confused,correct?

History is not linear. When you type "git log", you may think that 4 and 4' follow each other, but try "gitk" or "git log --oneline --graph" to see a better view of history.

It's possible to have several times the same change applied to multiple branches (e.g. when doing cherry-picking), but having twice the same change in a row is not really possible.

Suppose your commit 4 removes the line "foobar". Then, commits 1, 2 and 3 have the line "foobar" (think of commits as snapshots in history, not as diff. 3 is a snapshot, and when you run "git show 3", it shows you the diff from 2 to 3). Commits 4 and 4' don't have it anymore, and then obviously 5, 6, 7 don't have it either. At the time of merge, Git will notice that neither of the merges to commit have the line "foobar" and the result 8 won't have it either.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

← back to recent threads