Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| git_submodules [2019/02/27 14:28] – [Adding a submodule -- Part 1] rpjday | git_submodules [2019/02/27 19:14] (current) – [Overview] rpjday | ||
|---|---|---|---|
| Line 2: | Line 2: | ||
| The good and the bad of submodules, using Wind River' | The good and the bad of submodules, using Wind River' | ||
| + | |||
| + | Stuff to add: | ||
| + | |||
| + | * '' | ||
| ===== Links ===== | ===== Links ===== | ||
| Line 301: | Line 305: | ||
| ==== The initial repository ==== | ==== The initial repository ==== | ||
| - | Add a submodule to the repo for the "Pro Git" book, which has no current submodules: | + | Add a submodule to the repo for the "Pro Git" book, which is clean and has no current submodules: |
| + | |||
| + | < | ||
| + | $ git status | ||
| + | On branch master | ||
| + | Your branch is up to date with ' | ||
| + | nothing to commit, working tree clean | ||
| + | $ | ||
| + | </ | ||
| < | < | ||
| Line 309: | Line 321: | ||
| - | === Adding a submodule === | + | ==== Adding a submodule === |
| < | < | ||
| $ git submodule add https:// | $ git submodule add https:// | ||
| - | Cloning into '/ | + | Cloning into '/ |
| - | remote: Counting objects: | + | remote: Enumerating objects: 2, done. |
| - | remote: Compressing objects: 100% (13/13), done. | + | remote: Counting objects: |
| - | remote: Total 1161 (delta | + | remote: Compressing objects: 100% (2/2), done. |
| - | Receiving objects: 100% (1161/1161), 289.57 KiB | 969.00 KiB/s, done. | + | remote: Total 1189 (delta |
| - | Resolving deltas: 100% (690/690), done. | + | Receiving objects: 100% (1189/1189), 292.30 KiB | 1.82 MiB/s, done. |
| + | Resolving deltas: 100% (703/703), done. | ||
| $ | $ | ||
| </ | </ | ||
| - | === The end result === | + | Note that this has //not// committed the new submodule yet. So what //has// it done? |
| - | Note the submodule is already staged, ready for commit: | + | ==== The situation thus far ==== |
| < | < | ||
| $ git status | $ git status | ||
| On branch master | On branch master | ||
| - | Your branch is up-to-date with 'origin/ | + | Your branch is up to date with 'rpjday/ |
| Changes to be committed: | Changes to be committed: | ||
| Line 335: | Line 348: | ||
| new file: | new file: | ||
| - | new file: | + | new file: |
| $ | $ | ||
| </ | </ | ||
| - | === What's there? === | + | < |
| + | $ git submodule status | ||
| + | | ||
| + | $ | ||
| + | </ | ||
| + | |||
| + | The new '' | ||
| + | |||
| + | < | ||
| + | $ cat .gitmodules | ||
| + | [submodule " | ||
| + | path = coroutine2 | ||
| + | url = https:// | ||
| + | </ | ||
| + | |||
| + | The content of the new submodule working tree: | ||
| < | < | ||
| Line 353: | Line 381: | ||
| │ ├── images | │ ├── images | ||
| │ │ ├── event_model.dia | │ │ ├── event_model.dia | ||
| + | │ │ ├── event_model.png | ||
| ... etc etc ... | ... etc etc ... | ||
| </ | </ | ||
| - | ==== Adding a submodule -- what just happened? ==== | + | The content of the new submodule's Git directory: |
| - | + | ||
| - | === The new .gitmodules file === | + | |
| - | + | ||
| - | The new '' | + | |
| < | < | ||
| - | [submodule "coroutine2"] | + | $ ls -lF .git/ |
| - | path = coroutine2 | + | total 48 |
| - | url = https://github.com/ | + | drwxrwxr-x. 2 rpjday rpjday 4096 Feb 27 09:31 branches/ |
| - | </ | + | -rw-rw-r--. 1 rpjday rpjday |
| - | + | -rw-rw-r--. 1 rpjday rpjday | |
| - | === git diff === | + | -rw-rw-r--. 1 rpjday rpjday |
| - | + | drwxrwxr-x. 2 rpjday rpjday 4096 Feb 27 09:31 hooks/ | |
| - | There is no current '' | + | -rw-rw-r--. 1 rpjday rpjday 7299 Feb 27 09:33 index |
| - | + | drwxrwxr-x. 2 rpjday rpjday 4096 Feb 27 09:31 info/ | |
| - | < | + | drwxrwxr-x. 3 rpjday rpjday 4096 Feb 27 09:31 logs/ |
| - | $ git diff | + | drwxrwxr-x. 4 rpjday rpjday 4096 Feb 27 09:31 objects/ |
| + | -rw-rw-r--. 1 rpjday rpjday 1161 Feb 27 09:31 packed-refs | ||
| + | drwxrwxr-x. 5 rpjday rpjday 4096 Feb 27 09:31 refs/ | ||
| $ | $ | ||
| </ | </ | ||
| - | but examine what's been staged: | + | ==== Running "git diff" ==== |
| < | < | ||
| - | $ git diff --staged | + | $ git diff --cached |
| diff --git a/ | diff --git a/ | ||
| new file mode 100644 | new file mode 100644 | ||
| Line 392: | Line 419: | ||
| diff --git a/ | diff --git a/ | ||
| new file mode 160000 | new file mode 160000 | ||
| - | index 0000000..fc3cb67 | + | index 0000000..0233d35 |
| --- /dev/null | --- /dev/null | ||
| +++ b/ | +++ b/ | ||
| @@ -0,0 +1 @@ | @@ -0,0 +1 @@ | ||
| - | +Subproject commit | + | +Subproject commit |
| $ | $ | ||
| </ | </ | ||
| - | You can also use the '' | + | Abbreviated form: |
| < | < | ||
| Line 413: | Line 440: | ||
| + path = coroutine2 | + path = coroutine2 | ||
| + url = https:// | + url = https:// | ||
| - | Submodule coroutine2 0000000...fc3cb67 | + | Submodule coroutine2 0000000...0233d35 |
| $ | $ | ||
| </ | </ | ||
| Line 420: | Line 447: | ||
| < | < | ||
| - | $ git commit -am "added coroutine2 submodule" | + | $ git commit -a -m "added coroutine2 submodule" |
| - | [master | + | [master |
| 2 files changed, 4 insertions(+) | 2 files changed, 4 insertions(+) | ||
| | | ||
| - | | + | |
| $ | $ | ||
| </ | </ | ||
| Line 432: | Line 459: | ||
| < | < | ||
| $ git push origin master | $ git push origin master | ||
| - | </ | ||
| - | |||
| - | ===== Under the hood ===== | ||
| - | |||
| - | The submodule directory has a //file// named '' | ||
| - | |||
| - | < | ||
| - | $ cat coroutine2/ | ||
| - | gitdir: ../ | ||
| - | $ | ||
| - | </ | ||
| - | |||
| - | From the superproject, | ||
| - | |||
| - | < | ||
| - | $ ls -l .git/ | ||
| - | total 48 | ||
| - | drwxrwxr-x. 2 rpjday rpjday 4096 Feb 13 15:37 branches | ||
| - | -rw-rw-r--. 1 rpjday rpjday | ||
| - | -rw-rw-r--. 1 rpjday rpjday | ||
| - | -rw-rw-r--. 1 rpjday rpjday | ||
| - | drwxrwxr-x. 2 rpjday rpjday 4096 Feb 13 15:37 hooks | ||
| - | -rw-rw-r--. 1 rpjday rpjday 7299 Feb 13 15:38 index | ||
| - | drwxrwxr-x. 2 rpjday rpjday 4096 Feb 13 15:37 info | ||
| - | drwxrwxr-x. 3 rpjday rpjday 4096 Feb 13 15:37 logs | ||
| - | drwxrwxr-x. 4 rpjday rpjday 4096 Feb 13 15:37 objects | ||
| - | -rw-rw-r--. 1 rpjday rpjday 1174 Feb 13 15:37 packed-refs | ||
| - | drwxrwxr-x. 5 rpjday rpjday 4096 Feb 13 15:37 refs | ||
| - | $ | ||
| - | </ | ||
| - | |||
| - | ===== Cloning a project with submodules ===== | ||
| - | |||
| - | If you don't want to populate the submodule directories: | ||
| - | |||
| - | < | ||
| - | $ git clone https:// | ||
| - | </ | ||
| - | |||
| - | If you want to populate the submodule diredctories: | ||
| - | |||
| - | < | ||
| - | $ git clone --recurse-submodules https:// | ||
| - | </ | ||
| - | |||
| - | Populate all submodules after the fact: | ||
| - | |||
| - | < | ||
| - | $ git submodule update --init --recursive | ||
| </ | </ | ||