git - 没有子模块的嵌套 git 存储库?

标签 git

似乎父仓库中的 git 仓库不包含在父仓库的提交中,除非它被设置为子模块。是否可以覆盖此行为并将嵌套的 git repo 视为任何其他目录?我不想通过子模块依赖外部依赖,而是想使用 git 来管理项目内的这些依赖。

最佳答案

1/您可以通过以下方式覆盖它:

  • 要么 git config设置:设置环境变量$GIT_DIR
    您将嵌套 Git 工作树的 .git 目录定义为 external .git(在嵌套仓库和主仓库外部)
  • 或者通过将嵌套的 repo “N”设置在主 repo 外部,但检查 repo “N”主 repo :
core.worktree

Set the path to the root of the work tree. This can be overridden by the GIT_WORK_TREE environment variable and the --work-tree command line option

In both case, the idea is to have a nested worktree without any .git subdirectory in it.

2/ With submodules, the nested git repo is not really included in the parent repo.
A special entry is made in the parent tree to record the external Git SHA1.

new file mode 160000
index 0000000..4c4c5a2

另见“nature of Git submodules”(答案的第三部分)


九年后,this discussion很清楚:

I don't want to use submodules or crutches such as renaming all .git/ in subdirectories.
I just want that Git treats my .git/ subdirs as plain dirs with any other names.

布莱恩米。卡尔森 ( bk2204 ) 回答:

This is not possible.
You can't add a non-bare repository as a part of a parent repository without using submodules.
Git uses the .git directory to find the working tree and for safety reasons doesn't allow files or directories named that to be checked in.
Allowing users to check in .git directories would allow configuration and hooks to be stored as part of the repository, which would allow the execution of arbitrary code if someone cloned it and then changed into the subrepository.

关于git - 没有子模块的嵌套 git 存储库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2317652/

相关文章:

javascript - Js with git handle control version with the new module system client side

git - 如何在 git 的 post-checkout 钩子(Hook)中找出哪些文件发生了变化?

git - 管理黑客发布

git - 从主目录中删除 git(使用终端/命令行)

eclipse - 无法使用Eclipse key 文件

Xcode 项目显示两个 git 存储库(只有一个是正确的);提交给两者

git - 如何重新应用 git 中已恢复的更改

c++ - 在不同平台上处理#include 路径

ruby - 混帐 & ruby : How can I unset the GIT_DIR variable from inside a ruby script?

git - 并行开发多个功能并同时进行 git merge