GLaz
GLaz

Reputation: 295

Why git subtree merge doesn't delete files?

I have one branch ('other') attached as subtree to another ('master'). When I perform subtree merge from 'other' to 'master' it doesn't delete files which were deleted in 'other'.

Steps to reproduce on a clean repo:

$ touch master.txt
$ git add master.txt
$ git commit -m 'Initial master'
[master (root-commit) e2f5ffd] Initial master
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 master.txt
$ git checkout --orphan other
Switched to a new branch 'other'
$ touch other.txt
$ git add other.txt
$ git status
On branch other

Initial commit

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

        new file:   master.txt
        new file:   other.txt
$ git commit -m 'Initial other'
[other (root-commit) 408ee95] Initial other
 2 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 master.txt
 create mode 100644 other.txt
$ git checkout master
Switched to branch 'master'
$ git read-tree --prefix=other/ -u other
$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        new file:   other/master.txt
        new file:   other/other.txt
$ git commit -m 'Other subtreed'
[master f9ba0db] Other subtreed
 2 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 other/master.txt
 create mode 100644 other/other.txt
$ git checkout other
Switched to branch 'other'
$ git rm master.txt
rm 'master.txt'
$ git commit -m 'master.txt removed'
[other 1feef18] master.txt removed
 1 file changed, 0 insertions(+), 0 deletions(-)
 delete mode 100644 master.txt
$ git checkout master
Switched to branch 'master'
$ git merge --squash -s subtree --no-commit other
Squash commit -- not updating HEAD
Automatic merge went well; stopped before committing as requested
$ git status
On branch master
nothing to commit, working directory clean

So after merge of deleted file - there is nothing to commit. Is it correct behavior? And how to make merge with deleted files?

Upvotes: 3

Views: 395

Answers (1)

GLaz
GLaz

Reputation: 295

The correct way to merge subtree to have everything merged is:

git merge -s recursive -Xsubtree=other --no-commit other

So, it is without --squash and has a little different form (from git v2).

Upvotes: 1

Related Questions