Merge conflicts often occur when multiple users are concurrently making edits to the same section in the same file. This makes it difficult for Git to determine which change should be kept. The merge conflict process gives users the ability to sort out which lines of code should be kept and committed. Here we'll show you how you'd resolve merge conflicts in the IDE!
Running into a merge conflict
In this example we have a column that represents the total number of orders your customer has ever had. It's currently named
number_of_orders but your stakeholder feels like this could be named better.
You and a teammate make changes to the column name, but have gone two separate routes. You rename this column to
total_number_of_orders and your teammate has renamed it
Your teammate has committed their change first, so you encounter a merge conflict when you press commit.
You will then see that the git action bar shows
commit and resolve... instead of
commit indicating that the Cloud IDE has detected some conflicts that need to be addressed. You should also see the conflict section marked with some flags:
<<<<<< HEADyour current code======conflicting code>>>>>> (some branch identifier)
Encountering Merge Conflicts
You could run into this merge conflict in 2 possible ways:
- Pulling changes from your main branch when someone else has merged a conflicting change
- Committing your changes to the same branch when someone else has already committed their change first (this scenario)
The way to resolve either scenario will be exactly the same!
- Choose which lines of code you'd like to preserve. Delete the rest, make sure to also delete the special flags that highlight the merge conflict.
- Press save! You will notice the line highlights disappearing, returning to a plain white background, which is a good sign that you've resolved the conflict successfully!
Repeat this process for every file that has a merge conflict.
Completing the process
When you've resolved all the merge conflicts, the last step would be to commit the changes you've made!
The easiest way to identify whether you've successfully resolved all conflicts would be to check the file tree. If all the files highlighted in red have a file icon next to it, instead of the warning sign, you should be good to go!
You will also know it's time to commit when you press the
commit and resolve... button and the modal does not have any warning messages about unresolved merge conflicts!
When you're ready, write your commit message as you normally would and press the