Pregunta

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 :)

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top