当worktree是父目录时,无法添加git子模块

时间:2016-04-18 12:21:38

标签: git version-control git-submodules dotfiles

我正在使用$HOME/.dotfiles下的git存储库跟踪我的dotfiles,该存储库配置为跟踪$HOME中的文件(我使用git config core.worktree "../../")。

只要涉及常规文件,此方法就可以正常工作,但在尝试添加子模块时失败。例如:

~/.dotfiles $ git submodule add git@github.com:ardagnir/vimbed.git ../../.vim/bundle/vimbed/
fatal: Not a git repository (or any parent up to mount point /home)       
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).

我还尝试了../.vim/...$HOME/.vim/...

core.worktree设置为repo默认目录的父级时,是否可以添加子模块?如果是这样,我应该如何使用什么命令?

3 个答案:

答案 0 :(得分:0)

您为什么要跟踪整个$ HOME目录?将所有dotfiles维护在.dotfiles文件夹/ repo中然后将这些文件符号链接到您的家中更合理,例如使用您的配置和子模块创建一个文件夹$HOME/.dotfiles/vim,然后将其链接到$HOME/.vim

您还可以轻松地使用dotfiles的设置脚本,备份以前的配置,然后将您的dotfiles链接到$HOME

答案 1 :(得分:0)

我没有尝试使用git submodule,但是git stash设置环境变量$GIT_DIR或使用参数--git-dir有效。例如,git --git-dir=./.git stash(看起来很愚蠢甚至是必要的)。

请参阅: https://git-scm.com/docs/git.htmlhttps://stackoverflow.com/posts/6392941/edit

答案 2 :(得分:0)

git子模块不要遵循core.worktree设置 -尝试:

git --git-dir="$HOME/dotfiles" --work-tree="$HOME"