删除文件后合并Git子树时出现的问题

删除文件后合并Git子树时出现的问题,git,git-merge,git-subtree,Git,Git Merge,Git Subtree,我想在我的一个项目中使用子树,并使用所描述的方法。如果从子树中删除了一些文件,则在将子树合并到子项目时会出现问题。在合并期间,文件删除似乎没有从子树集成分支传播到主分支 我正在Kubuntu 14.04上运行Git 1.9.1,sub_项目集成为我的主项目中的子树 修改一个文件并从我的子项目中删除另一个文件 提交修改 浏览我的主要项目 签出sub_项目集成分支 拉动修改(我看到修改文件的修改和删除删除的文件) 签出我的主项目的master分支 git diff tree-p sub_projec

我想在我的一个项目中使用子树,并使用所描述的方法。如果从子树中删除了一些文件,则在将子树合并到子项目时会出现问题。在合并期间,文件删除似乎没有从子树集成分支传播到主分支

我正在Kubuntu 14.04上运行Git 1.9.1
sub_项目
集成为我的主项目中的
子树

  • 修改一个文件并从我的
    子项目中删除另一个文件

  • 提交修改

  • 浏览我的主要项目

  • 签出sub_项目集成分支

  • 拉动修改(我看到修改文件的修改和删除删除的文件)

  • 签出我的主项目的
    master
    分支

  • git diff tree-p sub_project_branch
    表示修改了一个文件,删除了一个文件

  • 将我的子树集成分支合并到主分支(删除的文件仍然存在,而修改已经集成)

  • 以下是相应的命令:

    创建将用作子树的项目

    $ mkdir sub_project
    $ cd sub_project
    $ git init
    $ touch toto
    $ echo "-----------------" >> toto
    $ echo "- toto file">> toto
    $ echo "-----------------" >> toto
    $ touch tata
    $ echo "-----------------" >> tata
    $ echo "- tata file">> tata
    $ echo "-----------------" >> tata
    $ git add toto tata
    $ git commit -m "Initial commit"
    $ echo "echo toto" >> toto
    $ echo "echo tata" >> tata
    $ git commit -am "Add content to file"
    $ cd ..
    
    $ mkdir main_project
    $ cd main_project
    $ git init
    $ touch tutu
    $ echo "-----------------" >> tutu
    $ echo "- tutu file">> tutu
    $ echo "-----------------" >> tutu
    $ git add tutu
    $ git commit -m "Add tutu file"
    
    $ mkdir sources
    $ git remote add sub_project_remote ../sub_project
    $ git fetch sub_project_remote
    $ git checkout -b sub_project_branch sub_project_remote/master
    $ git checkout master
    $ git read-tree --prefix=sources/sub_project/ -u sub_project_branch
    $ git commit -am "Integration of subtree"
    
    $ ls *
    toto
    
    创建将使用子树的主项目

    $ mkdir sub_project
    $ cd sub_project
    $ git init
    $ touch toto
    $ echo "-----------------" >> toto
    $ echo "- toto file">> toto
    $ echo "-----------------" >> toto
    $ touch tata
    $ echo "-----------------" >> tata
    $ echo "- tata file">> tata
    $ echo "-----------------" >> tata
    $ git add toto tata
    $ git commit -m "Initial commit"
    $ echo "echo toto" >> toto
    $ echo "echo tata" >> tata
    $ git commit -am "Add content to file"
    $ cd ..
    
    $ mkdir main_project
    $ cd main_project
    $ git init
    $ touch tutu
    $ echo "-----------------" >> tutu
    $ echo "- tutu file">> tutu
    $ echo "-----------------" >> tutu
    $ git add tutu
    $ git commit -m "Add tutu file"
    
    $ mkdir sources
    $ git remote add sub_project_remote ../sub_project
    $ git fetch sub_project_remote
    $ git checkout -b sub_project_branch sub_project_remote/master
    $ git checkout master
    $ git read-tree --prefix=sources/sub_project/ -u sub_project_branch
    $ git commit -am "Integration of subtree"
    
    $ ls *
    toto
    
    创建子树

    $ mkdir sub_project
    $ cd sub_project
    $ git init
    $ touch toto
    $ echo "-----------------" >> toto
    $ echo "- toto file">> toto
    $ echo "-----------------" >> toto
    $ touch tata
    $ echo "-----------------" >> tata
    $ echo "- tata file">> tata
    $ echo "-----------------" >> tata
    $ git add toto tata
    $ git commit -m "Initial commit"
    $ echo "echo toto" >> toto
    $ echo "echo tata" >> tata
    $ git commit -am "Add content to file"
    $ cd ..
    
    $ mkdir main_project
    $ cd main_project
    $ git init
    $ touch tutu
    $ echo "-----------------" >> tutu
    $ echo "- tutu file">> tutu
    $ echo "-----------------" >> tutu
    $ git add tutu
    $ git commit -m "Add tutu file"
    
    $ mkdir sources
    $ git remote add sub_project_remote ../sub_project
    $ git fetch sub_project_remote
    $ git checkout -b sub_project_branch sub_project_remote/master
    $ git checkout master
    $ git read-tree --prefix=sources/sub_project/ -u sub_project_branch
    $ git commit -am "Integration of subtree"
    
    $ ls *
    toto
    
    检查子树是否集成良好

    $ ls *
    tutu
    
    sources:
    sub_project
    $ ls sources/sub_project
    tata
    toto
    
    $ ls sources/sub_project
    tata
    toto
    
    进入子树删除文件tata

    $ cd ../sub_project
    $ echo "#EOF" >> toto
    $ git add toto
    $ git rm tata
    $ git commit -m "Add EOF and remove tata"
    
    返回主项目以集成子树修改

    $ cd ../main_project
    $ git checkout sub_project_branch
    $ git fetch sub_project_remote
    $ git pull
    
    检查塔塔是否已在子树中删除

    $ mkdir sub_project
    $ cd sub_project
    $ git init
    $ touch toto
    $ echo "-----------------" >> toto
    $ echo "- toto file">> toto
    $ echo "-----------------" >> toto
    $ touch tata
    $ echo "-----------------" >> tata
    $ echo "- tata file">> tata
    $ echo "-----------------" >> tata
    $ git add toto tata
    $ git commit -m "Initial commit"
    $ echo "echo toto" >> toto
    $ echo "echo tata" >> tata
    $ git commit -am "Add content to file"
    $ cd ..
    
    $ mkdir main_project
    $ cd main_project
    $ git init
    $ touch tutu
    $ echo "-----------------" >> tutu
    $ echo "- tutu file">> tutu
    $ echo "-----------------" >> tutu
    $ git add tutu
    $ git commit -m "Add tutu file"
    
    $ mkdir sources
    $ git remote add sub_project_remote ../sub_project
    $ git fetch sub_project_remote
    $ git checkout -b sub_project_branch sub_project_remote/master
    $ git checkout master
    $ git read-tree --prefix=sources/sub_project/ -u sub_project_branch
    $ git commit -am "Integration of subtree"
    
    $ ls *
    toto
    
    在主分支中合并

    $ git checkout master
    $ git diff-tree -p sub_project_branch
    diff --git a/tata b/tata
    deleted file mode 100644
    index a4f4cc4..0000000
    --- a/tata
    +++ /dev/null
    @@ -1,4 +0,0 @@
    ------------------
    -- tata file
    ------------------
    -echo tata
    diff --git a/toto b/toto
    index 8dfbe14..98ae756 100644
    --- a/toto
    +++ b/toto
    @@ -2,3 +2,4 @@
     - toto file
     -----------------
     echo toto
    +#EOF
    
    $ git merge -v --squash --no-commit -X subtree=sources/sub_project -X theirs sub_project_branch
    
    合并后检查塔塔是否已被删除

    $ ls *
    tutu
    
    sources:
    sub_project
    $ ls sources/sub_project
    tata
    toto
    
    $ ls sources/sub_project
    tata
    toto
    
    我希望在主分支中看到对文件的修改和对另一个文件的删除,但是删除的文件仍然存在并被跟踪。文件的修改已完成,但似乎删除操作尚未“合并”

    我所期望的行为与下面的命令序列中所示的行为相同,它执行完全相同的操作,只是它们是在分支而不是子树中执行的。托托应该被修改,塔塔应该不再存在(或者至少不再被跟踪)

    根据我所看到的,子树合并似乎是一种复制,而不是真正的合并,这意味着如果源文件消失,那么相应的目标文件将保持不变,而不是被删除

    这种行为是正确的,还是我对子树合并应该做什么的理解是错误的

    我也问了这个问题,但我现在没有答案