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

unexpected git-merge result

From
DRDale Rowley <ddrowley3@juno.com>
Date
Feb 19, 2010, 21:35 UTC
Message-ID
<loom.20100219T202452-35@post.gmane.org>
Our branch history looked something like the following:
  B---C
 /     \
A---D---E---H
     \     /
      F---G

In commit D a few lines were added to a file, and then in commit G the same lines were removed. When branches E and G were merged, those lines unexpectedly re-appeared in the merge commit (H), even though no other commits had touched that file.

I think I understand why this happened: git-merge-base reports that the common ancestor for E and G is A. Since those lines don't appear in that file in commits A or G, git-merge assumes that they were added independently on branch E, so it decides to keep the lines in the merged result.

This merge problem arises because although A is the most recent common ancestor of branches E and G in general, it is *not* the most recent common ancestor as far as that single file is concerned. The most recent common ancestor for that particular file is commit D.

This is worrisome because I imagine the converse will also be a potential problem: lines are removed in commit D, and then re-added in commit G, and they will unexpectedly disappear in the merge (H). So my question is whether this is a bug in git (ie, shouldn't git be considering independent common ancestors for each file that is merged)? This doesn't seem like a particularly unique or rare scenario - how is everyone else preventing these kinds of problems?

Dale
Next: Junio C Hamano
Message 1 of 5 in “unexpected git-merge result”
  1. Dale RowleyFeb 19, 2010
  2. Junio C HamanoFeb 19, 2010
  3. Dale RowleyFeb 20, 2010
  4. Dmitry PotapovFeb 22, 2010
  5. Dale RowleyFeb 22, 2010

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.