Git Merge Guide - part 2

(these posts are part of the material I cover in my devops course)

Merge Conflicts

Preparations

Use your previous knowledge to preoare the following:

  • A repository called demo
  • A branch called feature1 with:
    • a file called file.txt
    • The file has 3 lines with the following content (copy and paste exactly these characters):
    11111111111
    22222222222
    33333333333
    
  • Make sure this is commited.
  • Add a new branch called feature2 that:
    • Starts when last section was completed (so feature2 has the same file and content)
    • Edit file.txt and add the following changes the middle line like this:
    11111111111
    22--------2
    33333333333
    
  • Add and commit this to feature2
  • Go back to feature1
  • Edit the file to this state:
11111111111
22++++++++2
33333333333
  • Add and commit

Conflict!!!

  • Go to branch feature1 and try to merge feature2:
1git checkout feature1
2git merge feature2
  • You should see a conflict.
    • Note that all changes were not done, even the new file that has no conflicts.
      (use git status to see this)
    • Edit file.txt to see how it was changed by the conflict.
  • Make the changes, by writing what you really want to be written to line 2.
  • Add everything that is not added
  • Commit