Sobes.tech
Junior — Middle

What methods can be used to resolve conflicts when working with Git and how to apply them?

sobes.tech AI

Answer from AI

Conflicts in Git occur when changes in the same part of a file are made in different branches. The main methods for resolving conflicts:

  1. Manual resolution:

    • Git marks conflicting sections in the file with <<<<<<<, =======, >>>>>>>.
    • You need to manually select or merge changes, remove the markers, and save the file.
  2. Using merge tools:

    • Visual merge tools (e.g., kdiff3, meld, built into IDEs) help compare versions and choose the necessary changes.
  3. Git commands:

    • git status will show files with conflicts.
    • After resolving conflicts, run git add <file> and then git commit.

Example:

git merge feature_branch
# conflict occurs
# open the file, fix the conflict
git add conflicted_file
git commit

It is important to carefully check changes to avoid losing important code.

What methods can be used to resolve conflicts when… - sobes.tech