git submodule
git
Uso
git submodule update --init --recursiveFija otro repositorio en un commit dentro del tuyo; un clon normal deja la carpeta vacía hasta update --init, y el padre apunta a un commit, no a una rama.
Opciones habituales
| Opción | Significado |
|---|---|
| add <url> <path> | pin another repository at a path |
| update --init | fill in a submodule folder that a clone left empty |
| --recursive | go into submodules of submodules |
| update --remote | move the pin to the tip of the tracked branch |
| status | the commit each submodule sits at |
| deinit <path> | unregister it |
| foreach <cmd> | run a command in each one |
Ejemplos
git submodule update --init --recursivethe command that fills empty submodule folders after a clone
git submodule add https://github.com/x/lib.git vendor/libadds a dependency as a submodule
git submodule update --remoteupdates the pinned commit to the branch tip
Lo confuso es que deshacer tiene varias formas: mover a dónde apunta una rama no es lo mismo que añadir un commit que la revierte.
Cómo leerlo
- Los corchetes [ ] marcan una parte que puedes omitir.
- Los puntos suspensivos … indican que puedes poner varios.
- Las opciones distinguen mayúsculas: en algunos comandos -r y -R no hacen lo mismo.
Preguntas
Q. ¿Qué hace git submodule?
Fija otro repositorio en un commit dentro del tuyo; un clon normal deja la carpeta vacía hasta update --init, y el padre apunta a un commit, no a una rama.
Q. ¿Cómo se escribe?
git submodule update --init --recursive — los corchetes marcan lo que puedes omitir.
Q. ¿Cuántas opciones vale la pena saber?
Aquí van 7; la lista completa está en man git. Este comando está en git.
Comandos relacionados
página man: man git-submodule