gpt4 book ai didi

git - 从 .gitmodules 恢复 git 子模块

转载 作者:IT王子 更新时间:2023-10-29 00:35:29 26 4
gpt4 key购买 nike

我有一个文件夹,它是一个 git 仓库。它包含一些文件和 .gitmodules 文件。现在,当我执行 git initgit submodule init 时,后一个命令输出什么也没有。如何帮助 git 查看在 .gitmodules 文件中定义的子模块,而无需再次手动运行 git submodule add

更新:这是我的 .gitmodules 文件:

[submodule "vim-pathogen"]
path = vim-pathogen
url = git://github.com/tpope/vim-pathogen.git
[submodule "bundle/python-mode"]
path = bundle/python-mode
url = git://github.com/klen/python-mode.git
[submodule "bundle/vim-fugitive"]
path = bundle/vim-fugitive
url = git://github.com/tpope/vim-fugitive.git
[submodule "bundle/ctrlp.vim"]
path = bundle/ctrlp.vim
url = git://github.com/kien/ctrlp.vim.git
[submodule "bundle/vim-tomorrow-theme"]
path = bundle/vim-tomorrow-theme
url = git://github.com/chriskempson/vim-tomorrow-theme.git

这是这个目录的 list :

drwxr-xr-x  4 evgeniuz 100 4096 июня  29 12:06 .
drwx------ 60 evgeniuz 100 4096 июня 29 11:43 ..
drwxr-xr-x 2 evgeniuz 100 4096 июня 29 10:03 autoload
drwxr-xr-x 7 evgeniuz 100 4096 июня 29 12:13 .git
-rw-r--r-- 1 evgeniuz 100 542 июня 29 11:45 .gitmodules
-rw-r--r-- 1 evgeniuz 100 243 июня 29 11:18 .vimrc

所以,毫无疑问,它是顶级的。 git 目录没有改变,只有 git init 完成了

最佳答案

git submodule init 只考虑已经在索引(即“暂存”)中的子模块进行初始化。我会编写一个解析 .gitmodules 的简短脚本,并针对每个 urlpath 对运行:

git submodule add <url> <path>

例如,您可以使用以下脚本:

#!/bin/sh

set -e

git config -f .gitmodules --get-regexp '^submodule\..*\.path$' |
while read path_key local_path
do
url_key=$(echo $path_key | sed 's/\.path/.url/')
url=$(git config -f .gitmodules --get "$url_key")
git submodule add $url $local_path
done

这是基于如何git-submodule.sh script本身解析 .gitmodules 文件。

关于git - 从 .gitmodules 恢复 git 子模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11258737/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com