background
When you merge different branches of code, you might change the same line of code, and then when you merge, you might have conflicts.
How do you solve it?
Select the target branch first
Began to merge
Select the source branch dev
conflict
Now there’s a conflict. Code conflicts occur because both branches modified the same line of code.
Resolve the conflict
If there are conflicts, how can they be resolved?
The illustration in the screenshot above gives a good idea of how to merge conflicting code.
It’s just a bunch of chunks
- On the left is the master branch
- On the right is the Dev branch
- In the middle is the final merge result
How do you merge?
Look directly at the red spot and click the red move arrow to keep the branch code. If you don’t want to modify the branch, just click the Red Cross arrow.
Or, if you want both branches of code, you can click on the red move arrow interface.
If you move them all over and find that there is a problem with code merging, you may need to manually fine-tune the order or position. In most cases, not even the order and location need to be fine-tuned, the merge is successful.
Successful Conflict resolution
Assuming that all you want to do now is keep the master changes, click the red move arrow of master to the left to move the changes to the center, and then click the Red Cross arrow of the Dev branch to indicate that the dev changes are not needed.
If all conflicts have been resolved, it will indicate that all conflicts have been resolved. Click Save.
The save is successful, indicating that the merge result has been committed to the local repository.
Note that the result of the merge is only committed to the local repository, not pushed to the remote repository. So the last step is to push local changes to the remote repository.
In addition, you can see that there are local changes that have not been committed to the remote repository, which is actually the result of the merge.
Push merges results into remote repositories
After push, what are the modifications?
As you can see, the final merge result is on the right, although it is the same as the master before the merge. That is because there are no changes to dev. If dev’s changes were made, this would be different from the original master — so the code on the right refers to the final merge result!
So what’s the code on the left? The code on the left is from the last commit of the Master branch.
As you can see, the master’s last commit ID is the same as the id on the left as seen in idea.
Ok, so once you understand that, you can just push.
Push a success.