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

git subtree merge deletes files in top directory

From
NHNikolai Hartmann <nikolai.hartmann@gmx.de>
Date
May 13, 2017, 09:20 UTC
Message-ID
<aa3f2a1c-42d2-06df-9823-c455c798ffb0@gmx.de>
Hi,

I'm trying to add a subtree which contains a folder with the same name as the subtree directory itself. Adding seems to work, but if i pull after the subtree remote changed, files in my top directory are deleted and everything seems to have "moved up" one directory - although i specify a subtree directory with "-P"

For example i start with top repository that contains one file:

. └── topfile

Now i try to add another repository as a subtree which looks like this:
.
├── afile
└── subrep
    └── anotherfile

Running `git subtree add -P subrep origin_subrep master --squash` on the top repository produces correctly

. ├── subrep │ ├── afile │ └── subrep │ └── anotherfile └── topfile

Now i change the subrep git by just adding files
.
├── afile
├── bfile
└── subrep
    ├── anotherfile
    └── yetanotherfile

When i try to merge these into the top repository by `git subtree pull -P subrep origin_subrep master --squash` i get

[...]
Removing topfile
Removing subrep/subrep/anotherfile
Removing subrep/afile
Merge made by the 'recursive' strategy.
 subrep/subrep/anotherfile => anotherfile | 0
 subrep/afile                             | 0
 topfile => yetanotherfile                | 0
 3 files changed, 0 insertions(+), 0 deletions(-)
 rename subrep/subrep/anotherfile => anotherfile (100%)
 delete mode 100644 subrep/afile
 rename topfile => yetanotherfile (100%)
And my top repository looks like

. ├── anotherfile └── yetanotherfile

The issue seems to be related to the subdirectory "subrep" of my repository "surep" having the same name - if i rename it to something else everything works as expected.

I could reproduce this behaviour in git 2.12.0 and the current next branch (v2.13.0-303-g4ebf30216)

Thanks, Nikolai

Message 1 of 1 in “git subtree merge deletes files in top directory”
  1. Nikolai HartmannMay 13, 2017

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.