git/list[1] front-page[2] threads[3] people[4] search[5] about
 

How to automatically correct an almost correct auto-merge?

From
SZEDER Gábor <szeder@ira.uka.de>
Date
Dec 16, 2011, 20:32 UTC
Message-ID
<20111216203215.GG1868@goldbirke>
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
Next: Seth Robertson
Message 1 of 4 in “How to automatically correct an almost correct auto-merge?”
  1. SZEDER GáborDec 16, 2011
  2. Seth RobertsonDec 16, 2011
  3. SZEDER GáborDec 17, 2011
  4. Neal KreitzingerDec 16, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.