question about a merge result

7 messages, 5 authors, 2016-06-15 · open the first message on its own page

question about a merge result

From: Francis Moreau <hidden>
Date: 2016-06-15 22:46:41

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

Re: question about a merge result

From: Michael Gaber <hidden>
Date: 2016-06-15 22:46:41

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

Re: question about a merge result

From: Jeff King <hidden>
Date: 2016-06-15 22:46:41

On Thu, Apr 30, 2009 at 02:34:43PM +0200, Michael Gaber wrote:
quoted
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

Re: question about a merge result

From: Francis Moreau <hidden>
Date: 2016-06-15 22:46:41

On Thu, Apr 30, 2009 at 4:26 PM, Jeff King [off-list ref] wrote:
On Thu, Apr 30, 2009 at 02:34:43PM +0200, Michael Gaber wrote:
quoted
quoted
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

Re: question about a merge result

From: Björn Steinbrink <hidden>
Date: 2016-06-15 22:46:41

On 2009.04.30 17:05:19 +0200, Francis Moreau wrote:
On Thu, Apr 30, 2009 at 4:26 PM, Jeff King [off-list ref] wrote:
quoted
On Thu, Apr 30, 2009 at 02:34:43PM +0200, Michael Gaber wrote:
quoted
quoted
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

Re: question about a merge result

From: Jeff King <hidden>
Date: 2016-06-15 22:46:41

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

Re: question about a merge result

From: Daniel Barkalow <hidden>
Date: 2016-06-15 22:46:41

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*
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help