Exercise - Merging small projects
Two previously independent repositories are to be merged into one large repository while preserving their history.
Tips
- With
fetch(andpull), you can also fetch history from foreign repositories without a common history with the current repository (keyword unrelated histories). merge(andpull) normally refuse to integrate unrelated histories- However, you can force this with
--allow-unrelated-histories.
- However, you can force this with
git mvmoves files and directories, e.g.,git mv file1 file1 targetdirectory.subtree add --prefix=<target-directory> <source-repository> <source-branch-or-version>: Embed another repository in a subdirectory.- If you don’t want to take over the entire history, you can specify
--squash. - Attention:
subtree addperforms a merge onHEADand therefore cannot be executed in an empty repository without commits.
- If you don’t want to take over the entire history, you can specify
Setup
Two repositories
backend.gitui.git
are already present.
Step 0 - START
Step 1 - Merge `git subtree`
Start in directory git-uebungen/aufgaben/modularisierung-repositorys-zusammenfuehren.
- Create a repo
applicationwith one commit. - Add
backend.gitin a subdirectorybackend. - Add
ui.gitin a subdirectoryui. - Examine the directory structure and commit graph
Step 2 - Merge with `fetch`, `mv` and `merge`
Start in directory git-uebungen/aufgaben/modularisierung-repositorys-zusammenfuehren.
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.