Git子模块添加:“在本地找到git目录”问题 [英] Git submodule add: “a git directory is found locally” issue
问题描述
您好,您可以按照 Git子模块添加:在本地找到git目录问题
我有很多这样的子模块目录有多少)
是否有可能初始化所有在.gitmodules中列出的子模块并强制全部取消。
此外,我想重置所有子模块并放弃本地存在的任何更改。
感谢:)
是否有可能初始化所有在.gitmodules中列出的子模块,并强制拉取所有子模块。
您可以删除所有子模块目录,然后重新运行 git submodule update
。也许这样:
git config -f .gitmodules --list |
awk -F ='$ 1〜/.path$/ {print $ 2}'|
xargs rm -rf
它使用 git config
在 .gitmodules
中列出配置,它会产生如下输出:
submodule.common.path = common
submodule.common.url = https://github.com/purpleidea/puppet-common.git
我们使用 awk
来提取路径信息,然后将它传递给 xargs
删除所有子模块目录。运行子模块更新
然后将重新填充这些目录:
$ git子模块更新
子模块路径'common':签出'2c0ed2844c606fd806bde0c02e47e79c88fab4a9'
另外,我想重置所有子模块并放弃本地存在的任何更改。
因为我们正在删除并重新 - 克隆子模块,这也将放弃任何本地更改。
Hi one follow up question to the question discussed in Git submodule add: "a git directory is found locally" issue
I have a lot of such submodule directories(not sure how many)
Is it somehow possible to initialize all the submoudules as listed in .gitmodules and force pull all of them.
Additionally I would like to reset all of the submodules and discard any changes locally present.
Thanks :)
Is it somehow possible to initialize all the submoudules as listed in .gitmodules and force pull all of them.
You could delete all the submodule directories and then re-run git submodule update
. Maybe like this:
git config -f .gitmodules --list |
awk -F= '$1 ~ /.path$/ {print $2}' |
xargs rm -rf
This uses git config
to list the configuration in .gitmodules
, which produces output like this:
submodule.common.path=common
submodule.common.url=https://github.com/purpleidea/puppet-common.git
We use awk
to extract the path information, and then pass that to xargs
to delete all the submodule directories. Running submodule update
will then re-populate those directories:
$ git submodule update
Submodule path 'common': checked out '2c0ed2844c606fd806bde0c02e47e79c88fab4a9'
Additionally I would like to reset all of the submodules and discard any changes locally present.
Because we're deleting and re-cloning the submodules, this will also discard any local changes.
这篇关于Git子模块添加:“在本地找到git目录”问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!