Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
200 views
in Technique[技术] by (71.8m points)

Nested git repositories without submodules?

It seems a git repo inside a parent repo isn't included in a commit on the parent unless it's setup as a submodule. Is it possible to override this behaviour and treat the nested git repo as any other directory? I don't want to rely on external dependencies through submodules but want to use git to manage these dependencies within the project.

question from:https://stackoverflow.com/questions/2317652/nested-git-repositories-without-submodules

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

1/ You could override that through:

  • either a git config setting: set the environment variable $GIT_DIR
    you define your .git directory of the nested Git working tree as an external .git (external to both the nested repo and the main repo)
  • or by setting your nested repo 'N' outside the main repo, but checkout that repo 'N' inside the main 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

See also "nature of Git submodules" (third part of the answer)


Nine years later, this discussion is quite clear:

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.

Brian m. Carlson (bk2204) answers:

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...