Conflict Resolution

A conflict occurs in Git when two or more people make changes to the same file in different branches. When you merge two branches that have conflicts, Git will show you a list of the files that have conflicts. You will need to resolve the conflicts before you can merge the branches. There are two ways to resolve conflicts:
  • Manually: This is the most common way to resolve conflicts. You will need to open the file that has the conflict and manually merge the changes from both branches.
  • Automatically: Git has a built-in conflict resolution tool that can automatically merge some conflicts. This tool is not perfect, but it can save you time if you are not comfortable resolving conflicts manually.
To resolve a conflict manually, follow these steps:
  1. Open the file that has the conflict in a text editor.
  2. Find the lines that have conflicts. These lines will have three sections:
    • The first section will show the changes that you made to the file in your branch.
    • The middle section will show the changes that someone else made to the file in their branch.
    • The third section will show the conflicting changes.
  3. Decide which changes you want to keep. You can keep all of your changes, all of the other person’s changes, or a combination of both.
  4. Once you have decided which changes to keep, delete the conflicting changes.
  5. Save the file.
To resolve a conflict automatically, use the git mergetool command. This command will open a graphical conflict resolution tool. Follow the instructions in the tool to merge the changes. Once you have resolved all of the conflicts, you can merge the branches. To do this, run the git merge command.
ADVERTISEMENT
ADVERTISEMENT