通过子模块显示Git中的外部代码依赖性 [英] To show external code dependency in Git by a submodule
问题描述
已解决的问题:通过子模块显示外部代码依赖关系:感谢 VonC !
在子模块路径上,声明子模块只是工作的一半。您仍然必须首次初始化子模块
git submodule git init
您需要 pull your submodules :
git submodule foreach git pull
$ b然后更新你的子模块
git submodule update
另见 Git submodules,part I and Git子模块,第二部分 $ b
.gitmodules
文件仅存储路径,但提交版本与主项目存储在一起。
我创建了一个 GitHub上的项目来演示发生了什么。请特别注意此提交,它添加了子模块,以查看发生了什么:
+子项目提交60be4b09f51d2560802ebd744893bb6f737ef57c
Solved Problem: to show external code dependency by submodules: Thanks to VonC!
Current Problem: to have a submodule without duplicate contents in two folders
A temporary solution to the current problem: to change the name of the folder to bin-github, since the name of the folder as a submodule is bin. This means I need to duplicate contents at my Home.
My HOME folder is dependent on ~/bin. I have files located at HOME at the repository Masi, while at ~/bin at the repo bin at Github. My relevant folder structure at Home:
~ |-- [drwxr-xr-x] bin | -- fileA ` -- folderA ...
I would like to know how to show make ~/bin a submodule of the Git at Masi.
How can you make ~/bin a submodule of my Git at ~/ ?
#3 Reply to VonC's comment:
My .gitmodules
[submodule "bin"] path = bin url = git://github.com/masi/bin.git
I feel that I do not need to add anymore the submodule again, since I have it in my .gitmodules.
I run
Sam master $ git submodule update Sam master $ git submodule foreach git pull Sam master $ ls bin
#2 Reply to VonC's answer:
I changed my .gitmodules to the following such that I do not have a duplicate copy of it in my home.
[submodule "bin"] path = bin url = git://github.com/masi/bin.git
This seems to be a different situation as I cannot pull the submodule-bin -folder similarly as above.
I get the following now at a fresh-cloned 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
I have the external repository in my .gitmodules. Why is it asking me to
git add
?
Reply to VonC's answer:
I run
git submodule add git://github.com/masi/bin.git bin-github-copy
because I cannot add a new repo with the same name as my existing folder
bin
.My .gitmodules is
[submodule "bin-github-copy"] path = bin-github-copy url = git://github.com/masi/bin.git
I run
git clone git://github.com/masi/Sam.git
I get an emty bin -directory.
How can I get the content of bin?
解决方案First, do not forget that with Git, you can not "add" a directory, only the content of at least one file within that directory.
Then you have two choices:
submodules, in order for Masi to refer a specific commit of your
[
files within a]
bin directory stored at GitHub (or to the latest commit of a branch, stored at GitHub)subtree merge, in order to mix the two repositories together and more easily follow modifications to files within bin directly from the Masi repository. That may be simpler in your scenario.
See this answer for more on those 2 strategies.
On the submodules path, declaring the submodule is only half the work. You still have to initialize your submodule the first time by
git submodule git init
You need then pull your submodules:
git submodule foreach git pull
and then update your submodule
git submodule update
See also this practical example with Git submodules, part I and 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中的外部代码依赖性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!