Skip to content

Instantly share code, notes, and snippets.

@jpic
Created June 29, 2015 11:51
Show Gist options
  • Save jpic/a50ff3ffca25a1418c84 to your computer and use it in GitHub Desktop.
Save jpic/a50ff3ffca25a1418c84 to your computer and use it in GitHub Desktop.
Demonstrate that git submodule tracks submodule per commit
[env] 29/06 2015 13:50:42 jpic@lue /tmp/test_git_submodule
$ git init root_repo
Initialized empty Git repository in /tmp/test_git_submodule/root_repo/.git/
[env] 29/06 2015 13:50:46 jpic@lue /tmp/test_git_submodule
$ git init sub_repo
Initialized empty Git repository in /tmp/test_git_submodule/sub_repo/.git/
[env] 29/06 2015 13:50:51 jpic@lue /tmp/test_git_submodule
$ cd sub_repo/
[env] 29/06 2015 13:50:52 jpic@lue /tmp/test_git_submodule/sub_repo ()
$ echo foo > bar
[env] 29/06 2015 13:50:56 jpic@lue /tmp/test_git_submodule/sub_repo ()
$ git add bar
[env] 29/06 2015 13:50:57 jpic@lue /tmp/test_git_submodule/sub_repo ()
$ git commit -m initial
[master (root-commit) 71878c6] initial
1 file changed, 1 insertion(+)
create mode 100644 bar
[env] 29/06 2015 13:50:59 jpic@lue /tmp/test_git_submodule/sub_repo ()
$ cd ../root_repo/
[env] 29/06 2015 13:51:01 jpic@lue /tmp/test_git_submodule/root_repo ()
$ git submodule add /tmp/test_git_submodule/sub_repo/ subm
Cloning into 'subm'...
done.
[env] 29/06 2015 13:51:11 jpic@lue /tmp/test_git_submodule/root_repo ()
$ git status
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: .gitmodules
new file: subm
[env] 29/06 2015 13:51:15 jpic@lue /tmp/test_git_submodule/root_repo ()
$ git commit -m "Added subm"
[master (root-commit) d26200e] Added subm
2 files changed, 4 insertions(+)
create mode 100644 .gitmodules
create mode 160000 subm
[env] 29/06 2015 13:51:19 jpic@lue /tmp/test_git_submodule/root_repo ()
$ ls -l subm/
total 4
-rw-r--r-- 1 jpic superadmin 4 Jun 29 13:51 bar
[env] 29/06 2015 13:51:20 jpic@lue /tmp/test_git_submodule/root_repo ()
$ cd ../sub_repo/
[env] 29/06 2015 13:51:23 jpic@lue /tmp/test_git_submodule/sub_repo ()
$ echo aoeu > aoeu
[env] 29/06 2015 13:51:25 jpic@lue /tmp/test_git_submodule/sub_repo ()
$ git add aoeu
[env] 29/06 2015 13:51:27 jpic@lue /tmp/test_git_submodule/sub_repo ()
$ git commit -m "extra file"
[master 26d8571] extra file
1 file changed, 1 insertion(+)
create mode 100644 aoeu
[env] 29/06 2015 13:51:31 jpic@lue /tmp/test_git_submodule/sub_repo ()
$ cd ../root_repo/
[env] 29/06 2015 13:51:33 jpic@lue /tmp/test_git_submodule/root_repo ()
$ git status
On branch master
nothing to commit, working directory clean
[env] 29/06 2015 13:51:34 jpic@lue /tmp/test_git_submodule/root_repo ()
$ cd ..
[env] 29/06 2015 13:51:37 jpic@lue /tmp/test_git_submodule
$ git clone --recursive root_repo/ new_root
Cloning into 'new_root'...
done.
Submodule 'subm' (/tmp/test_git_submodule/sub_repo/) registered for path 'subm'
Cloning into 'subm'...
done.
Submodule path 'subm': checked out '71878c672a791192565f3ee6d6eeb2872cc45e80'
[env] 29/06 2015 13:51:43 jpic@lue /tmp/test_git_submodule
$ cd new_root/
[env] 29/06 2015 13:51:47 jpic@lue /tmp/test_git_submodule/new_root ()
$ ls -l subm/
total 4
-rw-r--r-- 1 jpic superadmin 4 Jun 29 13:51 bar
[env] 29/06 2015 13:51:51 jpic@lue /tmp/test_git_submodule/new_root ()
$ cd subm/
[env] 29/06 2015 13:51:53 jpic@lue /tmp/test_git_submodule/new_root/subm ()
$ git pull
You are not currently on a branch. Please specify which
branch you want to merge with. See git-pull(1) for details.
git pull <remote> <branch>
[env] 29/06 2015 13:51:55 jpic@lue /tmp/test_git_submodule/new_root/subm ()
$ git remote add submodule_origin /tmp/test_git_submodule/sub_repo/
[env] 29/06 2015 13:52:21 jpic@lue /tmp/test_git_submodule/new_root/subm ()
$ git pull
You are not currently on a branch. Please specify which
branch you want to merge with. See git-pull(1) for details.
git pull <remote> <branch>
[env] 29/06 2015 13:52:23 jpic@lue /tmp/test_git_submodule/new_root/subm ()
$ git pull origin master
From /tmp/test_git_submodule/sub_repo
* branch master -> FETCH_HEAD
Updating 71878c6..26d8571
Fast-forward
aoeu | 1 +
1 file changed, 1 insertion(+)
create mode 100644 aoeu
[env] 29/06 2015 13:52:26 jpic@lue /tmp/test_git_submodule/new_root/subm ()
$ cd ..
[env] 29/06 2015 13:52:28 jpic@lue /tmp/test_git_submodule/new_root ()
$ git add -p
diff --git a/subm b/subm
index 71878c6..26d8571 160000
--- a/subm
+++ b/subm
@@ -1 +1 @@
-Subproject commit 71878c672a791192565f3ee6d6eeb2872cc45e80
+Subproject commit 26d8571fc34a9619a50bcaad603e5dc18ea6ace8
Stage this hunk [y,n,q,a,d,/,e,?]? y
[env] 29/06 2015 13:52:30 jpic@lue /tmp/test_git_submodule/new_root ()
$ git commit -m "Submodule update"
[master 784b5f3] Submodule update
1 file changed, 1 insertion(+), 1 deletion(-)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment