这是我在这里的第一个问题,对不起,如果它不好。
我使用git备份了一些家庭文件,其中包括vim插件,我经常把它作为git repo,所以我在自己的仓库中有几个git repos。 可悲的是,当我使用
时,这些子目录没有被添加 git add . -A
在我的主文件夹的副本上。
我找到了一些解决方案:
还有其他办法吗?
如果我可以将每个subrepo添加为常规文件,我会好的,但缺点是会跟踪更改两次。
答案 0 :(得分:0)
扩展@Greduan和我的评论:
您可以使用git submodule add <repo> <path>
添加本地git repo作为子模块。
根据submodule add
上的Git SCM文档:
这需要至少一个参数:
<repository>
。 可选参数<path>
是克隆子模块存在于超级项目中的相对位置。
TL; DR:如果<repo>
和<path>
相同,则可以避免将子仓库克隆到父仓库
假设我们在./
中有一个父回购,在./some/folder/child-repo
有一个子回购。
您可以添加子模块,而无需通过以下方式克隆它:
git submodule add ./some/folder/child-repo ./some/folder/child-repo #same location
这将在其当前位置添加child-repo
作为子模块。
Git会输出类似:Adding existing repo at 'some/folder/child-repo' to the index
。
如果您运行git status
,您应该会看到两个准备提交的新文件:
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: .gitmodules
# new file: some/folder/child-repo
#
.gitmodules
是描述模块的文件,另一个文件是子repo表示。
将子模块提交到父仓库:git commit -m 'add child-repo as submodule'
此时,您在 child-repo 中提交的任何提交都会显示在父回购中,如下所示:
# 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: some/folder/child-repo (new commits)
#
然后,您可以运行git submodule update
来更新父级回购。你有它 - 没有不必要的重复或额外的提交:)
警告:如果您在父级中运行submodule update
后需要使用子级仓库,您会发现子级仓库将位于分离的HEAD中状态。这在git submodule
手册更新部分中有记录。
您可以在子仓库中使用git checkout master
(或您正在使用的任何分支)修复此问题。
答案 1 :(得分:0)
我可以建议切换到vim-addon-manager或Vundle来保留第三方插件。主要思想是将vimrc名称添加到要安装的插件中,但配置VAM / Vundle以将其安装到VCS未跟踪的位置。然后,如果你想从备份恢复,你允许(VAM)或明确询问(Vundle,如果我没有误会)安装你在配置中列出的所有插件。
文档中的VAM甚至还有一个功能(列在Installation部分下面),它将首先检查VAM是否已经安装,如果不安装则安装它,然后继续使用插件。
此变体不再需要子模块来代替解决它们的问题。
您可能也会发现有趣的comparison between VAM and other plugins with similar purpose。