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:
-
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.
- Git marks conflicting sections in the file with
-
Using merge tools:
- Visual merge tools (e.g.,
kdiff3,meld, built into IDEs) help compare versions and choose the necessary changes.
- Visual merge tools (e.g.,
-
Git commands:
git statuswill show files with conflicts.- After resolving conflicts, run
git add <file>and thengit 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.