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

Re: git merge bug: creating new files in one branch in a directory that is renamed in another

From
Shawn O. Pearce <spearce@spearce.org>
Date
Jan 21, 2007, 08:44 UTC
Message-ID
<20070121084405.GB10632@spearce.org>
In-Reply-To
<45B3224B.3020800@gmail.com>
Liraz Siri <liraz.siri@gmail.com> wrote:
> I'm running a few tests to figure out when git does the right thing on
> merges, and I've discovered that git does not do the right thing if you
> are creating new files in one branch in a directory that is renamed in
> another.
Well, it depends on your definition of "the right thing" as to
whether or not Git does it.  :-)
 
> Merging edits of files in dir/ in one branch and renaming dir/ to
> newdir/ in another branch works, but if you create files in the renamed
> dir/ then after the merge they will still remain in dir/, rather than
> newdir/.

Yes. We don't actually track directories, we track contents of files. Renaming a directory in one branch and adding a file to that directory in the other branch does not imply that after the merge the new file belongs in the renamed location. Nor does it imply it should be in the old location, but that is where we currently put it.

We probably could modify merge-recursive to rename new files added by the second branch if:

 - the file from the second branch does not exist in the merge base
 (hence it was added by the second branch);
 - the file from the second branch is located under a path where
 a prefix of directories exists within the merge base;
 - all files in the merge base under that path prefix were either
 deleted or renamed to the another path prefix by the first branch.

but I'm not sure how often that occurs in practice that its worth implmenting, as the implementation is slightly non-trivial. Especially since it needs to be done for both sides.

-- 
Shawn.
Previous: Liraz SiriNext: Johannes Schindelin
Message 2 of 3 in “git merge bug: creating new files in one branch in a directory that is renamed in another”
  1. Liraz SiriJan 21, 2007
  2. Shawn O. PearceJan 21, 2007
  3. Johannes SchindelinJan 21, 2007

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.