这里M表示主站,MS表示带子模块的主站,FB表示FooBranch。
在Mb点,FooBranch已经从master创建。在MSd点,master中一个名为FooDir的子目录已经被改成了一个子模块。现在,master应该与该子模块合并到FooBranch中。我们分别在master和FooBranch的MSe和FBd点。FooDir在两个分支中都存在,在master中它是一个子模块,但它只是FooBranch中的一个子目录。从现在开始,它也应该像在master中一样,成为FooBranch中的一个子模块。
$ git status
On branch master
”Your branch is up to date with 'origin/master'”
$ git checkout FooBranch
error: The following untracked working tree files would be overwritten by checkout:
FooDir/blablabla
Aborting
$ git checkout -f FooBranch
warning: unable to rmdir 'FooDir': Directory not empty
Checking out files: 100% (2315/2315), done.
Branch 'FooBranch' set up to track remote branch 'FooBranch' from 'origin'.
Switched to a new branch 'FooBranch'
$ git merge master
fatal: refusing to merge unrelated histories
$ git merge master --allow-unrelated-histories
Loads of CONFLICTS
$ git rebase master
...
Adding FooDir/abc.txt
error: refusing to lose untracked file at 'FooDir/abc.txt'
CONFLICT (file/directory): There is a directory with name FooDir in First snapshot of the ... Adding FooDir as FooDir~HEAD
error: Failed to merge in the changes.
Patch failed at 0001 First snapshot of the X interface.
FooBranch中的所有变化都是独立于master分支的。FooBranch中的FooDir目录应该改为子模块,并且应该是主分支的复制粘贴。
如何才能做到这个合并。
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
(commit or discard the untracked or modified content in submodules)
modified: FooDir (modified content)
我也试过 $ git checkout master FooDir
和 $ git submodule update --init
......没有用!
$ cat .git/config
[submodule "FooDir"]
active = true
url = [email protected]:path/FooDir.git
这些命令解决了这个问题。
$ git checkout FooBranch -f
$ git checkout master FooDir
$ cd FooDir/
$ git reset --hard HEAD
$ git clean -fdx
$ git pull