我有一个包含Git存储库的Git存储库。
repo1/
.git/
files
repo2/
.git/
files
files
这种架构是否可行?
我有一个包含Git存储库的Git存储库。
repo1/
.git/
files
repo2/
.git/
files
files
这种架构是否可行?
160000
',用于子模块,但也适用于简单的嵌套仓库)。add
或 commit
只会应用于一个仓库,而不是其他仓库。
git submodule 允许从父仓库引用嵌套子仓库,并保持对子仓库的精确引用。160000
或gitlink
。 这里是一个关于gitlinks行为的示例。 - Josh Leegit fast-import
手册的链接,这是 Git 中唯一明确提到 gitlink
是什么的文档。 - VonCgit add .
或者 git add inner-repo
,结果会是一个 git 链接,就像这里描述的那样。但是,如果你执行 git add inner-repo/
(带有斜杠),那么它会添加仓库内部的文件,并开始跟踪它们,就像跟踪任何其他文件一样(除了 inner-repo/.git
,它会被忽略)。因此,结果是两个仓库单独跟踪文件,它们不知道彼此的存在。 - spelufo我使用这种结构已经有一段时间了,子仓库目录在外部仓库的.gitignore文件中指定。
这让我的编辑器(PhpStorm)的git工具感到困惑,它总是希望提交到外部仓库,但除此之外都能正常工作。我将整个外部仓库(包括所有内部仓库)作为一个项目加载到编辑器中。这样就可以在处理内部仓库时轻松搜索和查看外部仓库的代码。
我在任何我正在处理的仓库中使用Git bash进行所有Git操作。
子模块可能是更好的方法。我还没有时间去调查它们是否能更好地与PhpStorm配合使用。
是的,您可以使用这种模式。我过去曾将SVN外部引用带入git-svn克隆中。现在子模块可能处理得更好,但当时不适合我的需求。
您需要将以下内容添加到repo1/.git/info/exclude中,以确保repo2中的更改不会与repo1混合:
repo2
git submodule add
添加它们,所有这些软件包都将成为子模块。如果您修改嵌套的.git存储库中的 some_file
,则可能会看到类似于此的内容:~/project_root $ git status
# On branch master
# 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: vendor/nested_repo (modified content)
.git
!/.git
git add
命令。请注意,存储库路径中的尾部斜杠是必须的。~/project_root $ git add vendor/some_repo/ vendor/another_repo/
vendor/some_repo
中的some_file
,看看有什么不同:~/project_root $ git status
# On branch master
# 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)
#
# modified: vendor/some_repo/some_file
project_root
中运行git add --all
,然后再运行git commit "Changes ..."
。还有软件包管理解决方案。
Git子模块确实可以让您按照所描述的架构进行开发,而Git子树提供了类似的解决方案,许多人更喜欢使用它。
在我看来,软件包管理软件是任何复杂项目不可或缺的一部分。我喜欢Composer,因为它支持直观的工作流程。
不幸的是,PhpStorm不支持Git子模块: