已解决的问题:通过子模块显示外部代码依赖性:感谢 VonC !
当前问题:拥有 a submodule without duplicate contents in two folders
当前问题的临时解决方案:将文件夹名称改为bin-github,因为子模块的文件夹名称是bin。这意味着我需要在我的主页上复制内容。
我的 HOME 文件夹依赖于 ~/bin。 我的文件位于存储库 Masi 的 HOME 中,而在 Github 的存储库 bin 中的 ~/bin 中。我在首页的相关文件夹结构:
~
|-- [drwxr-xr-x] bin
| -- fileA
` -- folderA
...
我想知道如何在 Masi 上展示如何让 ~/bin 成为 Git 的子模块。
如何使 ~/bin 成为我位于 ~/的 Git 的子模块?
#3 回复 VonC 的评论:
我的.gitmodules
[submodule "bin"]
path = bin
url = git://github.com/masi/bin.git
我觉得我不需要再添加子模块了,因为我已经在我的 .gitmodules 中了。
我跑
Sam master $ git submodule update
Sam master $ git submodule foreach git pull
Sam master $ ls bin
#2 回复VonC的回答:
我将我的 .gitmodules 更改为以下内容,这样我家里就没有它的副本了。
[submodule "bin"]
path = bin
url = git://github.com/masi/bin.git
这似乎是一种不同的情况,因为我无法像上面那样 pull 出 submodule-bin -文件夹。
我现在在新克隆的 git-repo 中得到以下内容
Sam master $ git submodule git init
error: pathspec 'git' did not match any file(s) known to git.
error: pathspec 'init' did not match any file(s) known to git.
Did you forget to 'git add'? # I am not sure what this means
Sam master $ git submodule foreach git pull
Sam master $ git submodule update
我的 .gitmodules 中有外部存储库。为什么要我 git add
?
回复VonC的回答:
我跑
git submodule add git://github.com/masi/bin.git bin-github-copy
因为我无法添加与现有文件夹 bin
同名的新存储库。
我的 .gitmodules 是
[submodule "bin-github-copy"]
path = bin-github-copy
url = git://github.com/masi/bin.git
我跑
git clone git://github.com/masi/Sam.git
我得到一个空的 bin 目录。
如何获取bin的内容?
最佳答案
首先,不要忘记使用 Git,您不能“添加”目录,只能“添加”该目录中至少一个文件的内容。
那么你有两个选择:
submodules , 为了让 Masi 引用存储在 GitHub 中的
[
files within a]
bin 目录的特定提交(或存储在 GitHub 中的分支的最新提交)subtree merge ,以便将两个存储库混合在一起,并且更容易地直接从 Masi 存储库中对 bin 中的文件进行修改。在您的场景中,这可能更简单。
参见 this answer有关这两种策略的更多信息。
在子模块路径上,声明子模块只是工作的一半。你仍然需要通过
第一次初始化你的子模块git submodule git init
然后你需要pull your submodules :
git submodule foreach git pull
然后更新你的子模块
git submodule update
另请参阅 Git submodules, part I 的实际示例和 Git submodules, part II .
The
.gitmodules
file only stores the paths, but the commit version does get stored with the main project.
I created a project on GitHub to demonstrate what happens. Specifically look at this commit, which adds the submodule, to see what’s going on:
+Subproject commit 60be4b09f51d2560802ebd744893bb6f737ef57c
关于git - 通过子模块显示 Git 中的外部代码依赖性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1145422/