Hello! I'm trying to use subtrees. I've learned that there are two ways to go about it: using 'git subtree', which I've decided against, or "manually", which is what I'm doing.
When I try to merge a new commit from the "subtree" branch, I observe all kinds of *silent* failures. For example, there is a commit that removes three files in the subtree directory. - On my first attempt to merge it, it removed three completely different files in another directory. - On my second attempt, it removed only two of the three files. - On my third attempt, it said that "Merge went well", but there was no merge commit at all. - On my fourth attempt, there was a commit, but it was empty (no changes). In all cases, there was no warning, no output to notice that something went wrong - it always seems "successful", so I have to double-check everything. And this operation is as trivial as it gets - if even this can't be handled reliably, then I can't imagine how do people use it. So I guess I'm doing something wrong. Here is an example. The Git version I'm using is 2.39.2 (Debian Bookworm). # Create a new repo, add some files, add more files in 'utils/' subdirectory $ git init Initialized empty Git repository in /tmpfs/poc/.git/ $ touch a b c d e $ git add ? $ git commit -m "Initial commit" [master (root-commit) 172da89] Initial commit 5 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 a create mode 100644 b create mode 100644 c create mode 100644 d create mode 100644 e $ mkdir utils && cd utils $ touch f g h $ git add ? $ git commit -m "Add utils" [master 156233d] Add utils 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 utils/f create mode 100644 utils/g create mode 100644 utils/h $ cd .. # Split 'utils/' into a separate "subtree" branch $ git checkout -b utils Switched to a new branch 'utils' $ git filter-branch --subdirectory-filter utils Rewrite 156233d93120ccf4371dcd63cbcf1c5599c03abe (1/1) (0 seconds passed, remaining 0 predicted) Ref 'refs/heads/utils' was rewritten $ ls -lh total 0 -rw-r--r-- 1 kami kami 0 29 Oct 2023 19:26 f -rw-r--r-- 1 kami kami 0 29 Oct 2023 19:26 g -rw-r--r-- 1 kami kami 0 29 Oct 2023 19:26 h $ git graph --oneline --decorate * e9ef662 (HEAD -> utils) Add utils $ git status On branch utils nothing to commit, working tree clean # Update the 'utils' branch (mimick fetching the upstream branch) $ touch x $ git add x $ git commit -m "Add x" [utils 95deda7] Add x 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 x $ touch y $ git add y $ git commit -m "Add y" [utils e2dd4e2] Add y 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 y $ touch z $ git add z $ git commit -m "Add z" [utils b85ef2c] Add z 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 z # Merge the updates into the master branch $ git checkout master Switched to branch 'master' $ git merge -s subtree --allow-unrelated-histories --squash utils Squash commit -- not updating HEAD Automatic merge went well; stopped before committing as requested $ git status On branch master Changes to be committed: (use "git restore --staged <file>..." to unstage) new file: utils/x new file: utils/y new file: utils/z $ git commit [master 90bffcb] Add x y z 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 utils/x create mode 100644 utils/y create mode 100644 utils/z # Now update 'utils' again $ git checkout utils Switched to branch 'utils' $ rm x y z $ git commit -a [utils 85e7775] Delete XYZ 3 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 x delete mode 100644 y delete mode 100644 z # And merge this update $ git checkout master Switched to branch 'master' $ git merge -s subtree --allow-unrelated-histories --squash utils Squash commit -- not updating HEAD Automatic merge went well; stopped before committing as requested # OK, everything went fine, now let's check and commit this: $ git status On branch master nothing to commit, working tree clean # WTF? $ git graph --oneline --decorate * 90bffcb (HEAD -> master) Add x y z * 156233d (refs/original/refs/heads/utils) Add utils * 172da89 Initial commit # WTF??? $ git merge -s subtree --allow-unrelated-histories --squash utils Squash commit -- not updating HEAD Automatic merge went well; stopped before committing as requested # But at least the files were removed, right? $ ls -lha utils/ total 0 drwxr-xr-x 2 kami kami 160 29 Oct 2023 19:28 . drwxr-xr-x 4 kami kami 180 29 Oct 2023 19:28 .. -rw-r--r-- 1 kami kami 0 29 Oct 2023 19:28 f -rw-r--r-- 1 kami kami 0 29 Oct 2023 19:28 g -rw-r--r-- 1 kami kami 0 29 Oct 2023 19:28 h -rw-r--r-- 1 kami kami 0 29 Oct 2023 19:28 x -rw-r--r-- 1 kami kami 0 29 Oct 2023 19:28 y -rw-r--r-- 1 kami kami 0 29 Oct 2023 19:28 z # WTF??? OK, let's try passing the subtree prefix: $ git merge -s subtree -X subtree=utils --allow-unrelated-histories --squash utils Squash commit -- not updating HEAD Automatic merge went well; stopped before committing as requested $ git status On branch master nothing to commit, working tree clean # Let's try the default strategy with passing the subtree prefix?.. $ git merge -X subtree=utils --allow-unrelated-histories --squash utils Squash commit -- not updating HEAD Automatic merge went well; stopped before committing as requested $ git status On branch master nothing to commit, working tree clean $ git onegraph * 90bffcb (HEAD -> master) Add x y z * 156233d (refs/original/refs/heads/utils) Add utils * 172da89 Initial commit # Let's try without squashing?.. $ git merge -s subtree -X subtree=utils --allow-unrelated-histories utils Merge made by the 'subtree' strategy. $ git graph --oneline --decorate * 9799659 (HEAD -> master) Merge branch 'utils' |\ | * 85e7775 (utils) Delete XYZ | * b85ef2c Add z | * e2dd4e2 Add y | * 95deda7 Add x | * e9ef662 Add utils * 90bffcb Add x y z * 156233d (refs/original/refs/heads/utils) Add utils * 172da89 Initial commit # OK, now the commit is there. So files are deleted, right? $ ls -lha utils/ total 0 drwxr-xr-x 2 kami kami 160 29 Oct 2023 19:28 . drwxr-xr-x 4 kami kami 180 29 Oct 2023 19:28 .. -rw-r--r-- 1 kami kami 0 29 Oct 2023 19:28 f -rw-r--r-- 1 kami kami 0 29 Oct 2023 19:28 g -rw-r--r-- 1 kami kami 0 29 Oct 2023 19:28 h -rw-r--r-- 1 kami kami 0 29 Oct 2023 19:28 x -rw-r--r-- 1 kami kami 0 29 Oct 2023 19:28 y -rw-r--r-- 1 kami kami 0 29 Oct 2023 19:28 z # Then what's in the commit? $ git diff $ git diff HEAD $ git show commit 97996594a7e527880389a2253ed8f887c130a070 (HEAD -> master) Merge: 90bffcb 85e7775 Author: darkpenguin <darkpeng...@posteo.de> Date: Sun Oct 29 19:29:34 2023 +0400 Merge branch 'utils' # Nothing! OK, maybe there is something wrong with the commit I'm merging? $ git checkout utils Switched to branch 'utils' $ git diff HEAD~1 diff --git a/x b/x deleted file mode 100644 index e69de29..0000000 diff --git a/y b/y deleted file mode 100644 index e69de29..0000000 diff --git a/z b/z deleted file mode 100644 index e69de29..0000000 # No, files are definitely deleted in this commit. But they are not when I merge it. -- You received this message because you are subscribed to the Google Groups "Git for human beings" group. To unsubscribe from this group and stop receiving emails from it, send an email to git-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/git-users/217673f3-9785-b184-6174-b363bb7aa79f%40posteo.de.