Solution to Step 0 - START
Solution to Step 1 - Integrating modules as submodules
Integrate the modules frontend.git
and backend.git
using submodule add
. Then examine the resulting directory structure.
application $ git submodule add ../frontend.git frontend
Cloning into '/workspaces/git-workshop/build/git-uebungen-en/loesungen/modularisierung-submodules/application/frontend'...
done.
application $ git submodule add ../backend.git backend
Cloning into '/workspaces/git-workshop/build/git-uebungen-en/loesungen/modularisierung-submodules/application/backend'...
done.
You can see that the modules are embedded as independent Git repositories with a separate .git
directory.
application $ ll frontend backend
backend:
total 4.0K
-rw-r--r-- 1 vscode vscode 181 service.java
frontend:
total 4.0K
-rw-r--r-- 1 vscode vscode 181 main.ts
Attention! The submodules have been added, but a commit is still missing.
application $ git status
On branch main
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: .gitmodules
new file: backend
new file: frontend
application $ git commit -m 'add frontend and backend'
[main f5a4fc3] add frontend and backend
3 files changed, 8 insertions(+)
create mode 100644 .gitmodules
create mode 160000 backend
create mode 160000 frontend
Solution to Step 2 - Adopting changes from a module
Go to the backend
repo, change the service.java
file, commit and push. Look at the resulting commit (show --stat
) Go to the application/backend
repo and fetch the changes using pull
. Look at the transferred commit.
$ cd backend
backend $ # Edit file service.java at line 8 on branch main by bjoern.
backend $ git commit -am "`service.java`: Edit file service.java at line 8 on branch main by bjoern. "
[main 5465a06] : Edit file service.java at line 8 on branch main by bjoern.
1 file changed, 1 insertion(+), 1 deletion(-)
/bin/bash: line 1: service.java: command not found
backend $ git show --stat
commit 5465a0638bf7e6f63a41baded2cf6cf770d6b659
Author: bjoern <kapitel26blog@gmail.com>
Date: Thu Jul 29 00:00:00 2021 +0000
: Edit file service.java at line 8 on branch main by bjoern.
service.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
backend $ git push
To ../backend.git
005d8aa..5465a06 main -> main
backend $ cd ..
$ cd application
application $ cd backend
backend $ git pull
Updating 005d8aa..5465a06
Fast-forward
service.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From /workspaces/git-workshop/build/git-uebungen-en/loesungen/modularisierung-submodules/backend
005d8aa..5465a06 main -> origin/main
backend $ cd ..
application $ git add backend
application $ git commit -am 'updated backend'
[main eaf467e] updated backend
1 file changed, 1 insertion(+), 1 deletion(-)
application $ cd ..
Solution to Step 3 - Transferring changes to a module
Go to subtrees/frontend
, change main.ts
and commit. Transfer the change to frontend.git
using push
. Look at the transferred commit in frontend.git
.
$ cd application
application $ cd frontend
frontend $ # Edit file main.ts at line 5 on branch main by bjoern.
frontend $ git commit -am "`main.ts`: Edit file main.ts at line 5 on branch main by bjoern. "
[main 357f243] : Edit file main.ts at line 5 on branch main by bjoern.
1 file changed, 1 insertion(+), 1 deletion(-)
/bin/bash: line 1: main.ts: command not found
frontend $ git push
To /workspaces/git-workshop/build/git-uebungen-en/loesungen/modularisierung-submodules/frontend.git
03baf80..357f243 main -> main
frontend $ cd ..
Don’t forget: commit changes in the parent repository.
application $ git add frontend
application $ git commit -m 'new version of frontend'
[main 8a4ffa3] new version of frontend
1 file changed, 1 insertion(+), 1 deletion(-)
application $ cd ..
$ cd frontend.git
frontend.git $ git show --stat
commit 357f243ea0f6d3c6f832fb0e0f41743e44376a61
Author: bjoern <kapitel26blog@gmail.com>
Date: Thu Jul 29 00:00:00 2021 +0000
: Edit file main.ts at line 5 on branch main by bjoern.
main.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
frontend.git $ cd ..
Solution to Step 4 - Cloning the parent repo
Clone application
to myapplication
. Examine the directory structure. Don’t forget to run submodule update
.
$ git clone application myapplication
Cloning into 'myapplication'...
done.
$ cd myapplication
The module directories are there but still empty:
myapplication $ ll frontend backend
backend:
total 0
frontend:
total 0
Now we fetch the modules:
myapplication $ git submodule update --init
Submodule path 'backend': checked out '5465a0638bf7e6f63a41baded2cf6cf770d6b659'
Submodule path 'frontend': checked out '357f243ea0f6d3c6f832fb0e0f41743e44376a61'
Submodule 'backend' (/workspaces/git-workshop/build/git-uebungen-en/loesungen/modularisierung-submodules/backend.git) registered for path 'backend'
Submodule 'frontend' (/workspaces/git-workshop/build/git-uebungen-en/loesungen/modularisierung-submodules/frontend.git) registered for path 'frontend'
Cloning into '/workspaces/git-workshop/build/git-uebungen-en/loesungen/modularisierung-submodules/myapplication/backend'...
done.
Cloning into '/workspaces/git-workshop/build/git-uebungen-en/loesungen/modularisierung-submodules/myapplication/frontend'...
done.
myapplication $ ll frontend backend
backend:
total 4.0K
-rw-r--r-- 1 vscode vscode 249 service.java
frontend:
total 4.0K
-rw-r--r-- 1 vscode vscode 244 main.ts
myapplication $ cd ..