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 --graph
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.
How conflict is represented
When a merge conflict occurs, the section is denoted by
>>>>>>>. 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
git merge --abortis used in this case.
- resolve conflicts.
Gitwill mark the conflicting place. After resolving the conflicting place, use
git addto add it to
index, and then use
git 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 the
HEADversion and the
- View the pre-merged version.
git show :1:filenameshows the version of the common ancestor,
git show :2:filenameshows the
HEADversion of the current branch,
git show :3:filenameshows the
MERGE_HEADversion of the opposite branch .