2015-10-16 55 views
1

我有一個分支('其他')作爲子樹附加到另一個('主')。當我從'other'執行子樹合併到'master'時,它不會刪除在'other'中刪除的文件。爲什麼git子樹合併不會刪除文件?

重現步驟在一個乾淨的回購:

$ 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 

所以刪除的文件的合併之後 - 沒有什麼承諾。這是正確的行爲嗎?以及如何使刪除的文件合併?

回答

1

合併子樹所擁有的一切正確的方式合併爲:

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

因此,它是沒有--squash,有一點點不同形式(從混帳V2)。

+0

這對我不起作用,我已經有了通過子樹合併添加的文件,並且稍後一旦刪除了您的命令不會刪除它們。它確實能夠正確引入其餘的更改 – LovesTha

相關問題