Git merge is used for branching and merging content from other branches into the current branch. For example, the branching structure is as follows:
Master /c0----C1----C2----C4 C3----C5 issuefix
Current Branch is master
$ git Checkout Master
Merge the contents of the Issuefix into:
$ git Merge Issuefix
If there is no conflict, the merge is complete. If there is a conflict, Git will prompt for conflicts in that file, such as the following:
<<<<<<< head:test.c
printf ("Test1″");
=======
printf ("Test2″");
>>>>>>> issuefix:test.c
You can see the top half of the ======= partition, which is the content in the HEAD (that is, the branch that was checked out when the merge command was run), and the lower part is the content in the Issuefix branch. The way to resolve conflicts is to either choose one or you can integrate it yourself. For example, you can solve this by replacing the content with the following:
printf ("Test2″");
This solution incorporates a subset of the two branches, and removes the <<<<<<<,=======, and >>>>>>> lines. After all the conflicts in all files have been resolved, running git add will mark them as resolved (resolved). Because once staged, the conflict is resolved. If you want to use a graphical interface tool to solve these problems, run Git mergetool, which invokes a visual merge tool and guides you through all conflicts:
$ git Mergetool
Merge tool candidates:kdiff3 Tkdiff Xxdiff meld Gvimdiff Opendiff emerge Vimdiff
Merging the files:index.html
Normal merge conflict for ' test.c ':
{Local}: Modified
{Remote}: Modified
Hit return to start Merge Resolution tool (KDIFF3):
The merged branch chart is as follows:
Master /c0----C1----C2----C4----C6 \ / C3----C5 issuefix
Note that the implementation of this merger, because the commit (C4) that the current master branch points to is not the direct ancestor that wants to merge the branch (Issuefix), Git has to do some processing. In this case, Git uses the end of the two branches (C4 and C5) and their common ancestor (C2) for a simple three-party merge. A new snapshot of the results of the tripartite merge and automatically creates a commit (C6) that points to it
After exiting the merge tool, Git will ask you if the merge was successful. If the answer is yes, it will save the relevant files for you to indicate that the status has been resolved. You can then use git commit to complete this merge submission.
Git merge Merge Branch