Woj*_*tek 7 git git-submodules
好的,我们有一个包含 3 个子模块的存储库。现在我们想将此子模块合并回主存储库,保留所有历史记录(好吧,使用子模块比有用更令人头疼)。我们该如何进行?
假设您有以下文件系统(并且假设您只有一个子模块,以简单地回答)
\nmyRepoRoot\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 myMainFiles/\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 submodule/\nRun Code Online (Sandbox Code Playgroud)\n你只需要做:
\n# Preparing the filesystems\ncd submodule\n# "submodule" is basically the path where you need your submodule code to be in the new repository,\n# e.g. app/code/x/y (<-- in this case you need to create multiple folders ofc, not just one like seen here)\nmkdir submodule\ngit mv file1 file2 dir1 dir2 submodule \ngit commit -am "Moved file"\n\n# Actually merging\ncd myRepoRoot\ngit remote add sub url_to_submodule\ngit fetch sub\ngit merge sub/master\nRun Code Online (Sandbox Code Playgroud)\n用文字解释一下:你有几棵树,没有共同的提交,你只需要合并这些树。这就是第二部分正在做的事情。
\n第一部分只需确保子模块的文件系统符合您的预期。
\n