【问题标题】:Why git subtree merge doesn't delete files?为什么 git subtree merge 不删除文件?
【发布时间】:2016-01-15 17:09:01
【问题描述】:

我有一个分支('other')作为子树附加到另一个('master')。当我执行从“其他”到“主”的子树合并时,它不会删除在“其他”中删除的文件。

在干净的 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

因此,在合并已删除文件后 - 没有什么可提交的。这是正确的行为吗?以及如何与已删除的文件进行合并?

【问题讨论】:

    标签: git merge git-subtree


    【解决方案1】:

    合并子树以合并所有内容的正确方法是:

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

    所以,它没有 --squash 并且有一点不同的形式(来自 git v2)。

    【讨论】:

    • 这对我不起作用,我有通过子树合并添加的文件,后来一旦删除,您的命令不会删除它们。它确实正确地带来了其余的变化
    • @Glaz 您找到解决此问题的方法了吗?我也面临这个问题。
    猜你喜欢
    • 2012-07-29
    • 1970-01-01
    • 2016-09-13
    • 2019-02-02
    • 2017-01-20
    • 2015-04-20
    • 2014-08-06
    • 2019-05-30
    • 2010-11-27
    相关资源
    最近更新 更多