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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top