When git submits a file, it happens to be the same file that someone else modified, which leads to conflicts

case scenario

Everyday, everyone in a project team maintains a project together. There are often situations where multiple people modify the same file, and they are submitted at the same time when they are submitted. The modification submitted first initiates a merge request to be merged and submitted later. After the person initiates the merge request, there will be a conflict, so someone will tell you that your code has a conflict. This is where you need to resolve the conflict.

Solution

For the conflicts generated above. You can do this.
First use git pull to update the latest code on your local develop branch.
insert image description here
Then switch to the branch that needs to resolve the conflict.
Use git checkout to switch to your own conflicting branch;
use git status to view the status;
use git merge to remotely branch your own current branch to merge other people's submissions into your own branch;
insert image description here
at this time, you can view it from the above figure You will see keywords similar to the following. CONFLICT, representing a conflict.
insert image description here
Use git status to view the status, you can see some files that you don’t seem to have modified, but the status shows that they have been modified. like below.
insert image description here
At this moment, it is dumbfounded. Then you can pull out the green-marked files in the cache.
Use the command: git add -i.
About the use of git add -i in my previous article:. Mentioned, available for review.
After pulling out the files in the cache area, use git status to view the status, and you can see a display similar to the following, the files have been pulled out from the temporary storage area to the work area.
insert image description here
You can see that it is still under the branch with "|MERGING". So here you can use the command git merge --abort command to exit MERGING.
insert image description here
Next, you can use git log to view the commit log, and then roll back. This method here is relatively stupid, because the author has not found other methods to solve this problem. Those who have different methods are welcome to give a solution, preferably in detail.
Then check the log and roll back to the node without conflicts.
insert image description here
The description in the green box is the submission that caused the conflict at that time, so roll back to the time when there is no conflict, that is, the last submission of the submission that caused the conflict. That is, the submission in the blue box in the figure, copy the number in the blue box. Use the command: git reset number to go back.
insert image description here
After the rollback, use git status to check the status to see if it is the status when it was not submitted after the original modification.
Then use git pull to update the latest code. An error may occur when pulling. At this time, you can use git stash to store your local modifications temporarily.
Use git pull again to pull the latest code.
insert image description here
Then use git stash pop to pull the previously staged code from the stage.
If there is a conflict, then resolve the conflict. You can compile the project. If an error is reported during compilation, locate the error point and modify the corresponding error.
After compiling without errors, submit the code.
The above method is relatively stupid and not a very good method. Guidance with a good method is welcome. The author is relatively slow. I hope that the guidance will be more detailed.

attached reference article

https://zhuanlan.zhihu.com/p/397267546#:~:text=%E6%89%8B%E5%8A%A8%E4%BF%AE%E6%94%B9%20READ.md%20% E6%96%87%E4%BB%B6%E5%8E%BB%E6%8E%89%E5%86%B2%E7%AA%81%EF%BC%8C%E6%AF%94%E5% A6%82%E4%BF%AE%E6%94%B9%E4%B8%BA%EF%BC%9A%20This%20is%20second%2Fthird%20commit.%20%E7%84%B6%E5%90 %8E%E4%BD%BF%E7%94%A8,add%20%E5%B0%86%E8%AF%A5%E6%96%87%E4%BB%B6%E6%B7%BB%E5 %8A%A0%E5%88%B0%E6%9A%82%E5%AD%98%E5%8C%BA%E3%80%82%20%E5%88%9A%E6%89%8D%E9 %81%87%E5%88%B0%E5%86%B2%E7%AA%81%E5%90%8E%EF%BC%8Cmerge%20%E8%BF%87%E7%A8%8B%E5 %B0%B1%E8%A2%AB%E4%B8%AD%E6%96%AD%E4%BA%86%EF%BC%8C%E7%8E%B0%E5%9C%A8%E4%BD %BF%E7%94%A8%20git%20merge%20–continue%20%E7%BB%A7%E7%BB%AD%E5%90%88%E5%B9%B6%E8%BF%87%E7 %A8%8B%E3%80%82
This article gives a solution to the conflict.

Guess you like

Origin blog.csdn.net/blqzj214817/article/details/129520341