git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Git merge: conflict is expected, but not detected
@ 2013-11-29 14:26 Evgeniy Ivanov
  2013-11-29 18:37 ` brian m. carlson
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Evgeniy Ivanov @ 2013-11-29 14:26 UTC (permalink / raw)
  To: git

Hi!

Let's say I have two identical branches: master and topic. In master I
remove some code, i.e. function bar(). In topic I do the same (commit)
and after some time I realize I need bar() and revert previous commit
with removal.
So I end with master with no bar() and topic with bar() in its
original state. When I merge I get code without bar() and no merge
conflict (recursive or resolve strategies). Is it possible to detect
such situations as conflicts? When bar() is C++ virtual there is no
possibility to catch this with compiler.

Please, CC me since I'm not subscribed.

Thanks in advance!

-- 
Cheers,
Evgeniy

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

* Re: Git merge: conflict is expected, but not detected
  2013-11-29 14:26 Git merge: conflict is expected, but not detected Evgeniy Ivanov
@ 2013-11-29 18:37 ` brian m. carlson
  2013-11-30  0:42 ` Kyle J. McKay
  2013-11-30  8:51 ` Jon Seymour
  2 siblings, 0 replies; 5+ messages in thread
From: brian m. carlson @ 2013-11-29 18:37 UTC (permalink / raw)
  To: Evgeniy Ivanov; +Cc: git

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

On Fri, Nov 29, 2013 at 06:26:25PM +0400, Evgeniy Ivanov wrote:
> Hi!
> 
> Let's say I have two identical branches: master and topic. In master I
> remove some code, i.e. function bar(). In topic I do the same (commit)
> and after some time I realize I need bar() and revert previous commit
> with removal.
> So I end with master with no bar() and topic with bar() in its
> original state. When I merge I get code without bar() and no merge
> conflict (recursive or resolve strategies). Is it possible to detect
> such situations as conflicts? When bar() is C++ virtual there is no
> possibility to catch this with compiler.

I don't believe so.  The problem you're seeing is that by default, git
considers only a small set of points for merges: the heads of the two
branches and the merge base.  So if one side has changed but the other
has not, the changed code takes effect.  This is not specifically a git
problem, but a three-way merge problem in general.

If you rebase instead of merge, then the code ends up the way you want
it, but this may or may not be appropriate for your workflow.

-- 
brian m. carlson / brian with sandals: Houston, Texas, US
+1 832 623 2791 | http://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: RSA v4 4096b: 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* Re: Git merge: conflict is expected, but not detected
  2013-11-29 14:26 Git merge: conflict is expected, but not detected Evgeniy Ivanov
  2013-11-29 18:37 ` brian m. carlson
@ 2013-11-30  0:42 ` Kyle J. McKay
  2013-11-30  8:51 ` Jon Seymour
  2 siblings, 0 replies; 5+ messages in thread
From: Kyle J. McKay @ 2013-11-30  0:42 UTC (permalink / raw)
  To: Evgeniy Ivanov; +Cc: git

On Nov 29, 2013, at 06:26, Evgeniy Ivanov wrote:
> Let's say I have two identical branches: master and topic. In master I
> remove some code, i.e. function bar(). In topic I do the same (commit)
> and after some time I realize I need bar() and revert previous commit
> with removal.
> So I end with master with no bar() and topic with bar() in its
> original state. When I merge I get code without bar() and no merge
> conflict (recursive or resolve strategies). Is it possible to detect
> such situations as conflicts? When bar() is C++ virtual there is no
> possibility to catch this with compiler.

You can do something like:

git checkout master
git merge -s ours --no-commit topic
# conflicts, if any, will happen during cherry-pick
git cherry-pick --no-commit ..topic
git commit -m "Merge branch 'topic'"

Which will give you a merge commit as though using "git merge" but it  
will have restored the bar() function.  However, depending on what's  
happened on the topic branch, you might have to wade through some  
conflicts that would not happen with a real "git merge" since cherry- 
pick will replay all the commits from the topic branch that aren't in  
master.  Maybe some day "git merge" will grow a "--cherry-pick" option.

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

* Re: Git merge: conflict is expected, but not detected
  2013-11-29 14:26 Git merge: conflict is expected, but not detected Evgeniy Ivanov
  2013-11-29 18:37 ` brian m. carlson
  2013-11-30  0:42 ` Kyle J. McKay
@ 2013-11-30  8:51 ` Jon Seymour
  2013-12-01 11:02   ` Evgeniy Ivanov
  2 siblings, 1 reply; 5+ messages in thread
From: Jon Seymour @ 2013-11-30  8:51 UTC (permalink / raw)
  To: Evgeniy Ivanov; +Cc: Git Mailing List

>From the perspective of topic there had been no change to the
definition of bar(), hence there was no change to contribute to the
eventual merge with master.

One way to avoid this kind of problem is to avoid making (or
cherry-picking) the same change on different branches, but instead use
a merge of a branch with a common base to implement changes needed on
multiple branches.

So, assuming you recognized the need to delete bar() from both topic
and master, create a new branch from the merge-base of topic and
master and delete bar() in that branch. Then merge this branch into
both topic and master.

If you subsequently decide to revert the removal of bar() on topic
then when you decide to merge topic back into master, git will see
that the removal branch has been merged into both branches and will
see the subsequent revert on topic as a change that needs to be merged
and you will get the result you are looking for.

So, as a general rule of thumb, try to avoid making the same change on
two different branches and instead factor out a change needed in
multiple places into a separate branch which is then merged into the
branches that need iit.


On Sat, Nov 30, 2013 at 1:26 AM, Evgeniy Ivanov <lolkaantimat@gmail.com> wrote:
> Hi!
>
> Let's say I have two identical branches: master and topic. In master I
> remove some code, i.e. function bar(). In topic I do the same (commit)
> and after some time I realize I need bar() and revert previous commit
> with removal.
> So I end with master with no bar() and topic with bar() in its
> original state. When I merge I get code without bar() and no merge
> conflict (recursive or resolve strategies). Is it possible to detect
> such situations as conflicts? When bar() is C++ virtual there is no
> possibility to catch this with compiler.
>
> Please, CC me since I'm not subscribed.
>
> Thanks in advance!
>
> --
> Cheers,
> Evgeniy
> --
> 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

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

* Re: Git merge: conflict is expected, but not detected
  2013-11-30  8:51 ` Jon Seymour
@ 2013-12-01 11:02   ` Evgeniy Ivanov
  0 siblings, 0 replies; 5+ messages in thread
From: Evgeniy Ivanov @ 2013-12-01 11:02 UTC (permalink / raw)
  To: Jon Seymour, sandals, mackyle; +Cc: Git Mailing List

Jon, Kyle, Brian,

Thanks a lot for your answers!

On Sat, Nov 30, 2013 at 12:51 PM, Jon Seymour <jon.seymour@gmail.com> wrote:
> From the perspective of topic there had been no change to the
> definition of bar(), hence there was no change to contribute to the
> eventual merge with master.
>
> One way to avoid this kind of problem is to avoid making (or
> cherry-picking) the same change on different branches, but instead use
> a merge of a branch with a common base to implement changes needed on
> multiple branches.
>
> So, assuming you recognized the need to delete bar() from both topic
> and master, create a new branch from the merge-base of topic and
> master and delete bar() in that branch. Then merge this branch into
> both topic and master.
>
> If you subsequently decide to revert the removal of bar() on topic
> then when you decide to merge topic back into master, git will see
> that the removal branch has been merged into both branches and will
> see the subsequent revert on topic as a change that needs to be merged
> and you will get the result you are looking for.
>
> So, as a general rule of thumb, try to avoid making the same change on
> two different branches and instead factor out a change needed in
> multiple places into a separate branch which is then merged into the
> branches that need iit.
>
>
> On Sat, Nov 30, 2013 at 1:26 AM, Evgeniy Ivanov <lolkaantimat@gmail.com> wrote:
>> Hi!
>>
>> Let's say I have two identical branches: master and topic. In master I
>> remove some code, i.e. function bar(). In topic I do the same (commit)
>> and after some time I realize I need bar() and revert previous commit
>> with removal.
>> So I end with master with no bar() and topic with bar() in its
>> original state. When I merge I get code without bar() and no merge
>> conflict (recursive or resolve strategies). Is it possible to detect
>> such situations as conflicts? When bar() is C++ virtual there is no
>> possibility to catch this with compiler.
>>
>> Please, CC me since I'm not subscribed.
>>
>> Thanks in advance!
>>
>> --
>> Cheers,
>> Evgeniy
>> --
>> 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



-- 
Cheers,
Evgeniy

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

end of thread, other threads:[~2013-12-01 11:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-29 14:26 Git merge: conflict is expected, but not detected Evgeniy Ivanov
2013-11-29 18:37 ` brian m. carlson
2013-11-30  0:42 ` Kyle J. McKay
2013-11-30  8:51 ` Jon Seymour
2013-12-01 11:02   ` Evgeniy Ivanov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).