# merge result

6 messages from 2011-09-09 to 2011-09-10. Participants: Lynn Lin, Andrew Ardill, Matthieu Moy.
Thread: https://gitlist.dev/t/28344

## Lynn Lin, 2011-09-09 10:54

Subject: merge result
Message-ID: <CAPgpnMRrSmVrXD__jxv3uNrek8up+scHp+_Kj8+=HX8tfweWzQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAPgpnMRrSmVrXD__jxv3uNrek8up%2BscHp%2B_Kj8%2B%3DHX8tfweWzQ%40mail.gmail.com

```
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, 2011-09-09 12:41

Subject: Re: merge result
Message-ID: <CAH5451=BpiN9P8gjL5TYQO+NSH913oXo1-bmscMXyy8QhFg8KQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAH5451%3DBpiN9P8gjL5TYQO%2BNSH913oXo1-bmscMXyy8QhFg8KQ%40mail.gmail.com
In-Reply-To: <CAPgpnMRrSmVrXD__jxv3uNrek8up+scHp+_Kj8+=HX8tfweWzQ@mail.gmail.com>

```
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:
> 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, 2011-09-09 13:00

Subject: Re: merge result
Message-ID: <vpqmxed6fby.fsf@bauges.imag.fr>
URL: https://gitlist.dev/e/vpqmxed6fby.fsf%40bauges.imag.fr
In-Reply-To: <CAPgpnMRrSmVrXD__jxv3uNrek8up+scHp+_Kj8+=HX8tfweWzQ@mail.gmail.com>

```
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, 2011-09-10 01:07

Subject: Re: merge result
Message-ID: <CAPgpnMTF4NEjPPXiBjRBG4yhDAdFpM0UM9kjBp7A06n=knfmmA@mail.gmail.com>
URL: https://gitlist.dev/e/CAPgpnMTF4NEjPPXiBjRBG4yhDAdFpM0UM9kjBp7A06n%3DknfmmA%40mail.gmail.com
In-Reply-To: <CAH5451=BpiN9P8gjL5TYQO+NSH913oXo1-bmscMXyy8QhFg8KQ@mail.gmail.com>

```
On Fri, Sep 9, 2011 at 8:41 PM, Andrew Ardill <andrew.ardill@gmail.com> wrote:
> 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

> 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
>>
>

```

## Lynn Lin, 2011-09-10 01:11

Subject: Re: merge result
Message-ID: <CAPgpnMTMPQQPkS-gKLvUJNKLfMWuAT-oA3NCiSRFxu7PknYsnA@mail.gmail.com>
URL: https://gitlist.dev/e/CAPgpnMTMPQQPkS-gKLvUJNKLfMWuAT-oA3NCiSRFxu7PknYsnA%40mail.gmail.com
In-Reply-To: <vpqmxed6fby.fsf@bauges.imag.fr>

```
On Fri, Sep 9, 2011 at 9:00 PM, Matthieu Moy
<Matthieu.Moy@grenoble-inp.fr> wrote:
> 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

> 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, 2011-09-10 11:35

Subject: Re: merge result
Message-ID: <vpqr53oeijq.fsf@bauges.imag.fr>
URL: https://gitlist.dev/e/vpqr53oeijq.fsf%40bauges.imag.fr
In-Reply-To: <CAPgpnMTMPQQPkS-gKLvUJNKLfMWuAT-oA3NCiSRFxu7PknYsnA@mail.gmail.com>

```
Lynn Lin <lynn.xin.lin@gmail.com> writes:

>>>    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/

```
