Solution to Step 0 - START
Solution to Step 1 - Merge git subtree
- Create a repo
application
with one commit. - Add
backend.git
in a subdirectorybackend
. - Add
ui.git
in a subdirectoryui
. - Examine the directory structure and commit graph
$ git init -b main application
Initialized empty Git repository in /workspaces/git-workshop/build/git-uebungen-en/loesungen/modularisierung-repositorys-zusammenfuehren/application/.git/
$ cd application
We create a first commit so that the subtree
command can be executed.
application $ # created file 'README'
application $ git add README
application $ git commit -am "Created file README on branch main by bjoern. "
[main (root-commit) 74f11b3] Created file README on branch main by bjoern.
1 file changed, 12 insertions(+)
create mode 100644 README
Then we add the repos with subtree
:
application $ git subtree add --prefix=backend ../backend.git main
git fetch ../backend.git main
From ../backend
* branch main -> FETCH_HEAD
Added dir 'backend'
application $ git subtree add --prefix=ui ../ui.git main
git fetch ../ui.git main
From ../ui
* branch main -> FETCH_HEAD
Added dir 'ui'
You can see that ui and backend have been merged including their history:
application $ git ls-tree -r --name-only HEAD
README
backend/src/Backend.java
backend/test/BackendTest.java
ui/src/UI.java
ui/test/UITest.java
application $ git log --oneline --graph
* f04721f Add 'ui/' from commit '5791af8bb65732c78dd9802fdac6bfe0aa218ced'
|\
| * 5791af8 Created file UITest.java on branch main by bjoern.
| * 292845b Created file UI.java on branch main by bjoern.
* 05a8fee Add 'backend/' from commit '4abbae294702c64cd9532bf814f7cb76db9fb963'
|\
| * 4abbae2 Created file BackendTest.java on branch main by bjoern.
| * 9ed7ede Created file Backend.java on branch main by bjoern.
* 74f11b3 Created file README on branch main by bjoern.
application $ cd ..
Solution to Step 2 - Merge with fetch
, mv
and merge
UI and backend should be merged in a new clone gesamt
. Follow the instructions in the chapter “Merging small projects”. Then examine the directory structure and commit graph.
$ git clone backend gesamt
Cloning into 'gesamt'...
done.
$ cd gesamt
Move backend files to subdirectory:
gesamt $ mkdir backend
gesamt $ git mv src test backend
gesamt $ git commit -m 'backend-Verzeichnis angelegt'
[main 0487992] backend-Verzeichnis angelegt
2 files changed, 0 insertions(+), 0 deletions(-)
rename {src => backend/src}/Backend.java (100%)
rename {test => backend/test}/BackendTest.java (100%)
Fetch content of the UI repository into a local branch uimain
:
gesamt $ git remote add ui ../ui/
gesamt $ git fetch ui
From ../ui
* [new branch] main -> ui/main
gesamt $ git switch -c uimain ui/main
branch 'uimain' set up to track 'ui/main'.
Switched to a new branch 'uimain'
Move UI files to subdirectory:
gesamt $ mkdir ui
gesamt $ git mv src test ui
gesamt $ git commit -m 'ui-Verzeichnis angelegt'
[uimain 43e14db] ui-Verzeichnis angelegt
2 files changed, 0 insertions(+), 0 deletions(-)
rename {src => ui/src}/UI.java (100%)
rename {test => ui/test}/UITest.java (100%)
Integrate uimain
:
gesamt $ git switch main
Your branch is ahead of 'origin/main' by 1 commit.
(use "git push" to publish your local commits)
Switched to branch 'main'
gesamt $ git merge uimain --allow-unrelated-histories
Merge made by the 'ort' strategy.
ui/src/UI.java | 12 ++++++++++++
ui/test/UITest.java | 12 ++++++++++++
2 files changed, 24 insertions(+)
create mode 100644 ui/src/UI.java
create mode 100644 ui/test/UITest.java
You can see that ui and backend have been merged including their history:
gesamt $ git ls-tree -r --name-only HEAD
backend/src/Backend.java
backend/test/BackendTest.java
ui/src/UI.java
ui/test/UITest.java
gesamt $ git log --oneline --graph
* dc42d8d Merge branch 'uimain'
|\
| * 43e14db ui-Verzeichnis angelegt
| * 5791af8 Created file UITest.java on branch main by bjoern.
| * 292845b Created file UI.java on branch main by bjoern.
* 0487992 backend-Verzeichnis angelegt
* 4abbae2 Created file BackendTest.java on branch main by bjoern.
* 9ed7ede Created file Backend.java on branch main by bjoern.
gesamt $ cd ..