gpt4 book ai didi

git - 为什么 git subtree merge 不删除文件?

转载 作者:太空狗 更新时间:2023-10-29 14:18:23 25 4
gpt4 key购买 nike

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

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

所以在 merge 删除的文件之后 - 没有什么可以提交的。这是正确的行为吗?以及如何 merge 已删除的文件?

最佳答案

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

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

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

关于git - 为什么 git subtree merge 不删除文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33179085/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com