When actually merging branches, it is not possible to merge successfully just by merging, and sometimes you may encounter code conflicts.
To demonstrate the problem, create a new branch
dev1
, and switch to the target branch, we can use
git checkout -
b dev1
completes the creation and switching actions in one step, an example is as follows:
- Modify the Test file under the dev1 branch, change the content of the file as follows, and make a submission, such as :
- Switch to the master branch and observe the contents of the Test file:
We found that after switching back, the content of the file changed from the old version. This phenomenon is normal and we can fully understand it now
- At this time, on the master branch, we modify the Test file again and submit it, as follows:
- Now, the master branch and the dev1 branch each have new commits, which become like this:
- In this case, Git can only try to merge the respective changes, but such a merge may have conflicts, as shown below:
- When we enter the Test file and find that there is a conflict in the Test file, we can directly view the content of the file. What we want to say is that Git will use <<<<<<<, =======, >>>>>>> to mark the conflicting content of different branches, as shown below :
- At this point we have to manually adjust the conflicting codes and submit the corrected results again! ! (It is important to submit again, don't forget )
- At this point, the conflict is resolved, and the state at this time becomes
- You can also see the merging of branches by using git log with parameters. For details, you can search for the usage of git log by yourself:
- Finally, don't forget that the dev1 branch can be deleted after use:
summary
The above is the solution to resolve git conflicts. To sum up, it needs to be modified manually.