Merge with Conflicts
Goal
- This project is about working and resolving conflicts during a merge.
Hints
- Try to solve the following tasks with the help of the Slides and the Cheatsheets.
- If you still run into problems, you'll find an expandable hint block for every task with a detailed description of the solution.
Task 1
- Leave the repository
mergeand create a new one:
cd .. # Leave the directory my-first-project
mkdir conflict # Create a new directory conflict
cd conflict # Change into that directory
git init # Create a new Git repository
Solution (Click on the arrow if you are stuck)
- Leave the directory
mergewith the commandcd ... - Run the command
pwdand you should see/root/workspaceas a result. - If you got a different result, run
cd /root/workspaceto change into the right directory. - When you are in the right directory, run
mkdir conflict. - Change into the newly created directory with
cd conflict. - Run
git initwhich creates a new git repository in the current directory.
Task 2
- Create a file
participants.txtwith the following content:Participants training 1: Philipp Lisa Rebecca Thomas Alexander
Task 3
- Create a new commit with the created file.
Solution (Click on the arrow if you are stuck)
- Create a new commit with
git add .andgit commit -m "{Enter your commit message here}".
Task 4
- Create a new branch
training2and change onto that branch.
Solution (Click on the arrow if you are stuck)
- Run the command
git switch -c training2.
Task 5
-
Add the following content to the file
participants.txt:Participants training 2: Markus Ramona Till Juliane
Task 6
- Create a commit with the changes.
Solution (Click on the arrow if you are stuck)
- Create a new commit with
git add .andgit commit -m "{Enter your commit message here}".
Task 7
- Change onto the
mainbranch.
Solution (Click on the arrow if you are stuck)
- Run the command
git switch main.
Task 8
- Delete the participants
ThomasandAlexander. Create a new commit.
Solution (Click on the arrow if you are stuck)
- Remove the names from
participants.txt. Save the file. - Create a new commit with
git add .andgit commit -m "{Enter your commit message here}".
Task 9
- Merge the changes of branch
training2intomain. Resolve the conflicts.
Solution (Click on the arrow if you are stuck)
- Start the merge with
git merge training2. - Open the file in the editor. VSCode automatically displays the areas with conflicts.
- As you can see, the changes do not only include the changes made in
training2but also the deleted names. - This is not a change we made on
training2so we do not want to merge that intomain. - Remove the names
ThomasandAlexandersuch that only the list of training 2 will be added and then save the file. - Mark the conflict as resolved by running
git add participants.txt. - Finish the merge with
git commit -m "{Enter your commit message here}".