All of lore.kernel.org
 help / color / mirror / Atom feed
* question about a merge result
@ 2009-04-30 12:21 Francis Moreau
  2009-04-30 12:34 ` Michael Gaber
  0 siblings, 1 reply; 7+ messages in thread
From: Francis Moreau @ 2009-04-30 12:21 UTC (permalink / raw)
  To: git

Hello,

I'm a little bit confused about a merge I have done and the result
suprised me. Thinking about it I'm still not convinced what should be
the result.

Here's the use case:

$ mkdir test-git && cd test-git
$ date > A
$ date > B
$ git init
$ git add .
$ git commit -m "Init"

So far I just created a repo with 2 files A and B

$ git branch b1
$ git rm B
$ git commit -m "remove B"

Now I created a branch 'b1' and remove B file in master branch

$ git checkout b1
$ git rm B
$ git commit -m "remove B"
$ git revert HEAD

Now on 'b1' I did the same as master but I thought that removing B was
a bad idea so I revert the previous commit

$ git checkout master
$ git pull . b1
$ ls B
ls: cannot access B: No such file or directory

So merging 'b1' into master removed the B file even if in branch 'b1'
I restored it.

Could anybody explain me why this is the correct behaviour and why not
file 'B' is not restored as it was done in branch 'b1' ?

thanks
-- 
Francis

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: question about a merge result
  2009-04-30 12:21 question about a merge result Francis Moreau
@ 2009-04-30 12:34 ` Michael Gaber
  2009-04-30 14:26   ` Jeff King
  0 siblings, 1 reply; 7+ messages in thread
From: Michael Gaber @ 2009-04-30 12:34 UTC (permalink / raw)
  To: Francis Moreau; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 1214 bytes --]

Francis Moreau schrieb:
> Hello,
> 
> I'm a little bit confused about a merge I have done and the result
> suprised me. Thinking about it I'm still not convinced what should be
> the result.
> 
> Here's the use case:
> 
> $ mkdir test-git && cd test-git
> $ date > A
> $ date > B
> $ git init
> $ git add .
> $ git commit -m "Init"
> 
> So far I just created a repo with 2 files A and B
> 
> $ git branch b1
> $ git rm B
> $ git commit -m "remove B"
> 
> Now I created a branch 'b1' and remove B file in master branch
> 
> $ git checkout b1
> $ git rm B
> $ git commit -m "remove B"
> $ git revert HEAD
> 
> Now on 'b1' I did the same as master but I thought that removing B was
> a bad idea so I revert the previous commit
> 
> $ git checkout master
> $ git pull . b1
> $ ls B
> ls: cannot access B: No such file or directory
> 
> So merging 'b1' into master removed the B file even if in branch 'b1'
> I restored it.
> 
> Could anybody explain me why this is the correct behaviour and why not
> file 'B' is not restored as it was done in branch 'b1' ?
> 
> thanks

well, I'd say the thing is, that in b1 there is no change at all to the
tree anymore, so when applied to master (without B) there is no b restored

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/x-pkcs7-signature, Size: 3643 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: question about a merge result
  2009-04-30 12:34 ` Michael Gaber
@ 2009-04-30 14:26   ` Jeff King
  2009-04-30 15:05     ` Francis Moreau
  0 siblings, 1 reply; 7+ messages in thread
From: Jeff King @ 2009-04-30 14:26 UTC (permalink / raw)
  To: Michael Gaber; +Cc: Francis Moreau, git

On Thu, Apr 30, 2009 at 02:34:43PM +0200, Michael Gaber wrote:

> > So merging 'b1' into master removed the B file even if in branch 'b1'
> > I restored it.
> > 
> > Could anybody explain me why this is the correct behaviour and why not
> > file 'B' is not restored as it was done in branch 'b1' ?
> 
> well, I'd say the thing is, that in b1 there is no change at all to the
> tree anymore, so when applied to master (without B) there is no b restored

That is exactly it. Git's 3-way merge doesn't look at the intervening
history at all. It looks _only_ at the two endpoints and their
merge-base (well, that is a bit of a simplification, as there may be
multiple merge-bases, but it is what is happening here).

-Peff

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: question about a merge result
  2009-04-30 14:26   ` Jeff King
@ 2009-04-30 15:05     ` Francis Moreau
  2009-04-30 15:39       ` Björn Steinbrink
                         ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Francis Moreau @ 2009-04-30 15:05 UTC (permalink / raw)
  To: Jeff King; +Cc: Michael Gaber, git

On Thu, Apr 30, 2009 at 4:26 PM, Jeff King <peff@peff.net> wrote:
> On Thu, Apr 30, 2009 at 02:34:43PM +0200, Michael Gaber wrote:
>
>> > So merging 'b1' into master removed the B file even if in branch 'b1'
>> > I restored it.
>> >
>> > Could anybody explain me why this is the correct behaviour and why not
>> > file 'B' is not restored as it was done in branch 'b1' ?
>>
>> well, I'd say the thing is, that in b1 there is no change at all to the
>> tree anymore, so when applied to master (without B) there is no b restored
>
> That is exactly it. Git's 3-way merge doesn't look at the intervening
> history at all. It looks _only_ at the two endpoints and their
> merge-base (well, that is a bit of a simplification, as there may be
> multiple merge-bases, but it is what is happening here).
>

Well, obviously it's how git works since it's what I got.

But the question was more about if the cortectness of the end result:
should 'B' removed after the merge.

IOW if someone works on its own branch remove B file and thought it
was a bad idea and restore it whereas another person remove B file but
miss the fact that it was a bad idea, does the merge should silently
remove B file ?

-- 
Francis

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: question about a merge result
  2009-04-30 15:05     ` Francis Moreau
@ 2009-04-30 15:39       ` Björn Steinbrink
  2009-04-30 15:42       ` Jeff King
  2009-05-01 16:27       ` Daniel Barkalow
  2 siblings, 0 replies; 7+ messages in thread
From: Björn Steinbrink @ 2009-04-30 15:39 UTC (permalink / raw)
  To: Francis Moreau; +Cc: Jeff King, Michael Gaber, git

On 2009.04.30 17:05:19 +0200, Francis Moreau wrote:
> On Thu, Apr 30, 2009 at 4:26 PM, Jeff King <peff@peff.net> wrote:
> > On Thu, Apr 30, 2009 at 02:34:43PM +0200, Michael Gaber wrote:
> >
> >> > So merging 'b1' into master removed the B file even if in branch 'b1'
> >> > I restored it.
> >> >
> >> > Could anybody explain me why this is the correct behaviour and why not
> >> > file 'B' is not restored as it was done in branch 'b1' ?
> >>
> >> well, I'd say the thing is, that in b1 there is no change at all to the
> >> tree anymore, so when applied to master (without B) there is no b restored
> >
> > That is exactly it. Git's 3-way merge doesn't look at the intervening
> > history at all. It looks _only_ at the two endpoints and their
> > merge-base (well, that is a bit of a simplification, as there may be
> > multiple merge-bases, but it is what is happening here).
> >
> 
> Well, obviously it's how git works since it's what I got.
> 
> But the question was more about if the cortectness of the end result:
> should 'B' removed after the merge.
> 
> IOW if someone works on its own branch remove B file and thought it
> was a bad idea and restore it whereas another person remove B file but
> miss the fact that it was a bad idea, does the merge should silently
> remove B file ?

You can also have that in the opposite direction. You make a bugfix in
your "master" branch, then cherry-pick that to "maint", but later
realize that you actually can't backport it like and and revert the
cherry-pick.  Then, later, you go to merge "maint" to "master" (to get
other bugfixes that were done directly on "maint"): Should the bugfix be
reverted on "master"? Obviously not.

git takes an approach that's easy to understand: Look at the changes
that the branch made compared to the common ancestor and apply those.
And for a "do it and then revert it" case, the answer is: There are no
changes.

Björn

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: question about a merge result
  2009-04-30 15:05     ` Francis Moreau
  2009-04-30 15:39       ` Björn Steinbrink
@ 2009-04-30 15:42       ` Jeff King
  2009-05-01 16:27       ` Daniel Barkalow
  2 siblings, 0 replies; 7+ messages in thread
From: Jeff King @ 2009-04-30 15:42 UTC (permalink / raw)
  To: Francis Moreau; +Cc: Michael Gaber, git

On Thu, Apr 30, 2009 at 05:05:19PM +0200, Francis Moreau wrote:

> Well, obviously it's how git works since it's what I got.

Yes, I meant also "this is what it is supposed to do, by design".

> But the question was more about if the cortectness of the end result:
> should 'B' removed after the merge.
> 
> IOW if someone works on its own branch remove B file and thought it
> was a bad idea and restore it whereas another person remove B file but
> miss the fact that it was a bad idea, does the merge should silently
> remove B file ?

Yes, it should be removed. And it has nothing to do with removal. Both
branches performed some action, but only one reverted it. Thus you still
have one branch wanting to make the change, and the other side leaving
it alone (in aggregate). So we want to take the changed side.

The only other thing that might make sense would be a conflict (because
both sides touched the same area and ended with different results). Git
doesn't try to find such a conflict because:

  1. Fundamentally, git cares about endpoints, not changelogs. So by
     design, you can arrive at the same tree state by many different
     routes and the merge will still happen in the same way.

  2. Finding such a conflict in the general case would be quite
     expensive, because you have to track every bit of content changed
     on one branch through every commit on the other branch, to see if
     they ever overlap.

If you want the result of the merge to keep it, you should do one of:

  - revert the removal in _both_ branches

  - merge with "--no-commit", add it back in, and then commit. The
    resulting commit will be a merge commit with the state you specify.

  - merge the early part of one branch, with the removal, into the other
    branch. Then "removed" becomes your basis for comparison, and then
    when you re-merge, the branch that re-adds it will be the only
    change.

-Peff

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: question about a merge result
  2009-04-30 15:05     ` Francis Moreau
  2009-04-30 15:39       ` Björn Steinbrink
  2009-04-30 15:42       ` Jeff King
@ 2009-05-01 16:27       ` Daniel Barkalow
  2 siblings, 0 replies; 7+ messages in thread
From: Daniel Barkalow @ 2009-05-01 16:27 UTC (permalink / raw)
  To: Francis Moreau; +Cc: Jeff King, Michael Gaber, git

On Thu, 30 Apr 2009, Francis Moreau wrote:

> But the question was more about if the cortectness of the end result:
> should 'B' removed after the merge.
> 
> IOW if someone works on its own branch remove B file and thought it
> was a bad idea and restore it whereas another person remove B file but
> miss the fact that it was a bad idea, does the merge should silently
> remove B file ?

Consider that deciding to remove a file can happen for a variety of 
reasons. Maybe one branch wiped it out accidentally and restored it, while 
the other did a bunch of work to make it obsolete and then removed it 
intentionally. There's no reason to think that the reason behind reverting 
the delete on one branch applies to the other delete.

Now, if the "b1" branch had gotten the delete from "master" by merging the 
same commit, and had reverted the commit that deleted the file, then git 
should (and does) include the file in the merge result, because then some 
user saw that particular deletion and decided it was wrong and reverted 
it. (Of course, git doesn't actually consider this in its merge algorithm, 
but, for clever mathematical reasons, what it does is equivalent.)

	-Daniel
*This .sig left intentionally blank*

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2009-05-01 16:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-30 12:21 question about a merge result Francis Moreau
2009-04-30 12:34 ` Michael Gaber
2009-04-30 14:26   ` Jeff King
2009-04-30 15:05     ` Francis Moreau
2009-04-30 15:39       ` Björn Steinbrink
2009-04-30 15:42       ` Jeff King
2009-05-01 16:27       ` Daniel Barkalow

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.