git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* How to automatically correct an almost correct auto-merge?
@ 2011-12-16 20:32 SZEDER Gábor
  2011-12-16 20:39 ` Seth Robertson
  2011-12-16 21:32 ` Neal Kreitzinger
  0 siblings, 2 replies; 4+ messages in thread
From: SZEDER Gábor @ 2011-12-16 20:32 UTC (permalink / raw)
  To: git

Hi,


Briefly:

Neighboring areas of a file are modified in two branches.  Git merges
the two branches without conflicts, but the result is not semantically
correct.  How can I teach git to produce the correct merge result when
performing the same merge later on?


Longer:

The following commands create a file and two branches, both of them
modifying the file by adding lines in the same area:

git init
cat >file <<\EOF
1

2
EOF
git add file
git commit -m file
git apply <<\EOF
diff --git a/file b/file
index 1c3e7efc..121366a2 100644
--- a/file
+++ b/file
@@ -1,3 +1,5 @@
 1

+a
+
 2
EOF
git commit -a -m a
git checkout -b branch HEAD^
git apply <<\EOF
diff --git a/file b/file
index 1c3e7efc..f2e91d4f 100644
--- a/file
+++ b/file
@@ -1,3 +1,6 @@
 1
+b
+
+c

 2
EOF
git commit -a -m 'b c'
git checkout master


At this point I merge 'branch' and git produces the following result:

$ git merge branch
Auto-merging file
Merge made by the 'recursive' strategy.
 file |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
$ cat file
1
b

c

a

2


Now, these changes and the merge above are the minimal receipe which
corresponds to a real merge I'm having trouble with at dayjob.  Just
imagine that '1' and '2' are the beginning and end of a function, 'b'
is the declaration of a new local variable, and 'a' and 'c' are new
code blocks.  As it happens, the semantically correct result would be
the following:

1
b

a

c

2

i.e. 'a' must be executed before 'c'.

I corrected the merge result manually, but these two branches are
merged a couple of times a day into an integration branch, and they
will likely cook for a few weeks, which means a lot of merges, and a
lot of manual corrections.  So I'm looking for a way to teach git to
produce the semantically correct merge result.  Something like
'rerere' would be great, but of course I can't use 'rerere' in this
case, because there are no merge conflicts at all...

Any ideas?  Did someone deal with similar issues before?


Thanks,
Gábor

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

end of thread, other threads:[~2011-12-17 11:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-16 20:32 How to automatically correct an almost correct auto-merge? SZEDER Gábor
2011-12-16 20:39 ` Seth Robertson
2011-12-17 11:07   ` SZEDER Gábor
2011-12-16 21:32 ` Neal Kreitzinger

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