git合并在错误的文件夹中

时间:2013-12-03 16:10:18

标签: git github merge git-subtree

我在git上有mainProjectshared library。 此shared library也位于subProject

我的工作流程

我通过克隆项目并创建一个分支来启动我的项目:

git clone https://github.com/user/mainProject.git main-project
git checkout -b fix

我在我的mainProject上工作,并在文件夹lib/shared library的根<)中添加了一个awesomeClass.php

新文件结构:

/index.php 
/page1.php
/lib/form/contact.php
/lib/awesomeClass.php*

* =新

之后我添加并提交我的更改。

git add lib/awesomeClass.php
git commit -m "added new awesome class that will blow your mind"

添加shared library的远程位置,获取它并将远程连接到本地分支

git remote add sharedlib https://github.com/user/sharedlib.git
git fetch sharedlib
git checkout -b sharedlib sharedlib/master

这将我的分支切换到sharedlib,我尝试将我的更改合并到,以便将shared library的相同更改发送到我的子项目。

 git merge --squash -s subtree --no-commit fix

这是它出错的地方,文件结构是(从sharedlib分支角度看):

/lib/form/contact.php
/lib/awesomeClass.php
合并后

/lib/form/index.php*
/lib/form/page1.php*
/lib/form/lib/form/contact.php*
/lib/form/lib/awesomeClass.php*

/lib/form/contact.php
/lib/awesomeClass.php

* =新

任何人都可以解释我如何只将shared library而非完整mainProject合并到错误的文件夹中? 谢谢!

1 个答案:

答案 0 :(得分:0)

关于子树合并策略,您正在遵循一些复杂的工作流程,但这已经过时了,而且这些日子要简单得多。

您正在寻找的是contrib command git-subtree,其中包含一个拆分功能,用于从与该子目录特别相关的主项目中提取更改,以便您可以将它们合并回上游到子项目