How to solve code conflicts in Gitlab? The following article will introduce to you the solution to see how to use the vscode tool to quickly resolve code conflicts. I hope it will be helpful to you!
I believe that many programmers who use git are afraid of git conflicts. When your project is about to go online, the test asks you to merge the code of the main branch and do a regression test. Then when you merge, a bunch of conflicting codes will directly make your scalp numb. Which conflict should be resolved and which piece of code should be deleted? Which piece of code cannot be deleted? After you complete the operation, you find that there is a bug, and then the launch is delayed. . .
First let’s take a look at how conflicts are caused
Scenario: If there is a file and you and another person modify a part of the code at the same time, he will After the modified code is submitted, when you pull the code, you will find conflicts with you. [Recommended learning: vscode tutorial, Programming teaching]
is shown in the picture:
In the picture, we are prompted that the READMD.me
file has a conflict, which requires us to resolve it manually, and then execute git add <conflict file name>
git rebase --continue
is enough.
So how to solve this problem?
With the help of the vscode prompt tool, we can see that
There are four options here
Accept Current Chagne
Select the current changeAccept Incoming Change
Select the merged changeAccept Both Change
Accept bothCompare Chagne
Compare ViewYou only need to check which part of the code you need to keep, and then choose different options to resolve the conflict. But before that, it's best to find the person who modified the code to confirm whether his code is useful or not, and then decide whether to keep it or not.
Then execute git add . && git rebase --continue
, and find the following scene:
Don’t panic at all , this allows you to fill in a commit information. By default, the last local commit information will be displayed. So how to edit this?
In fact, this is the operating mode of vim. You only need to execute the following lines of commands to get it done:
# 按i进入编辑模式i# 修改好commit信息# 按esc退出编辑模式esc# 最后使用:wq保存并退出vim模式:wq复制代码
At this point, a complete conflict resolution is completed.
If you are really unfamiliar with vim commands, don’t panic. After you modify the conflicting parts of the code, you can perform commit operations in the visual toolbar on the left. The effect is the same as vim operations. .
Finally, keep in mind that when you modify conflicting code, you must check who caused the conflicting code. Is the conflicting code online code? If it is online code, be sure not to delete it, otherwise bugs will crash your code as soon as it goes online. So be sure to communicate with the relevant person in charge.
For more knowledge about VSCode, please visit: vscode tutorial! !
The above is the detailed content of Detailed explanation of how Gitlab uses the vscode tool to quickly resolve code conflicts. For more information, please follow other related articles on the PHP Chinese website!