FixConflict
Conclusion
When Git can't automatically merge branches, it has to resolve conflicts first. After the conflict is resolved, commit again, and the merge is complete.
Conflict resolution is to manually edit the files that failed to be merged by Git to the content we want, and then submit them.
View the branch merge diagram:
git log --graphInfo
Conflicts generally occur in the following two situations:
- The code of the remote repository is lagging behind the local repository
- The code of the remote repository is far more than the local repository
When you haven't submitted the code, your colleagues have already submitted the code, which will cause the remote repository code to lead your code.
Caption
How conflict is represented
When a merge conflict occurs, the section is denoted by <<<<<<<, ======== and >>>>>>>. The part before ======== is the case of the current branch, and the part after ======== is the case of the incoming branch.
How to resolve conflicts
After seeing the conflict, you can choose between the following two ways:
- Decided not to merge. At this point, the only thing to do is to reset the
indexto theHEADnode.git merge --abortis used in this case. - resolve conflicts.
Gitwill mark the conflicting place. After resolving the conflicting place, usegit addto add it toindex, and then usegit committo generate merge nodes.
You can use the following tools to resolve conflicts:
- Use the merge tool.
git mergetoolwill invoke a visual merge tool to handle conflicting merges. - See the difference.
git diffwill display three-way diffs (the three-way comparison algorithm used in three-way merges). - See the diff for each branch.
git log --merge -p <path>will show the difference between theHEADversion and theMERGE_HEADversion. - View the pre-merged version.
git show :1:filenameshows the version of the common ancestor,git show :2:filenameshows theHEADversion of the current branch,git show :3:filenameshows theMERGE_HEADversion of the opposite branch .