我很难理解子模块是如何工作的。
我有一个远程存储库PARENT和一个远程存储库CHILD。我想让存储库CHILD成为存储库PARENT的子模块,所以当我签出PARENT时,CHILD也会被签出(进入PARENT的子文件夹)。所以我的第一次尝试是将PARENT设置为裸存储库。但是当我想添加子模块时:
[git ~/repositories/PARENT] git submodule add git://github.com/CHILD.git CHILD
fatal: /usr/libexec/git-core/git-submodule cannot be used without a working tree.
因此,我将PARENT 设为具有适当工作树的非裸存储库(即使我真的不需要该存储库中的工作树)。添加子模块很顺利。将PARENT克隆到本地存储库也很顺利,并且CHILD已按预期作为子文件夹检出。然后,当我想再次将本地存储库中的更改推送回PARENT时:
branch is currently checked out
error: refusing to update checked out branch: refs/heads/master
error: By default, updating the current branch in a non-bare repository
error: is denied, because it will make the index and work tree inconsistent
error: with what you pushed, and will require 'git reset --hard' to match
error: the work tree to HEAD.
error:
error: You can set 'receive.denyCurrentBranch' configuration variable to
error: 'ignore' or 'warn' in the remote repository to allow pushing into
error: its current branch; however, this is not recommended unless you
error: arranged to update its work tree to match what you pushed in some
error: other way.
error:
error: To squelch this message and still keep the default behaviour, set
error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
所以我不能在我的裸存储库中使用子模块,因为它有一个工作树,但是当我使用非裸存储库时,我不能签入,因为它有一个工作树?我在这里不明白什么?