Git merge Branch

Source: Internet
Author: User
Tags git mergetool

Git merge is used to merge branches and merge the contents of other branches into the current branch. For example, the branch structure is as follows:

                        master                         /C0 ---- C1 ---- C2 ---- C4                         \                         C3 ---- C5                                  \                                issueFix

The current branch is master.
$ Git checkout master

Put the content in issuefix merge in:
$ Git merge issuefix

If no conflict exists, merge completes. If there is a conflict, git will prompt that there is a conflict in that file, for example, the following conflict:

<Head: Test. c

Printf ("test1 ″);

========

Printf ("Test2 ″);

>>>>>>> Issuefix: Test. c

We can see that the upper half of the = separated is the head (that is, the master branch, which is running in merge
The content of the branch detected during command execution. The lower part is in the issuefix
The content in the branch. The solution to the conflict is simply one of the two or you can integrate them yourself. For example, you can solve this problem by replacing the content with the following:

Printf ("Test2 ″);

This solution each adopts part of the two branches and deletes
<, ======, And >>>>>
These rows. After resolving all conflicts in all files, run git add
Mark them as resolved ). Once saved, the conflict is resolved. If you want to use a graphical tool to solve these problems, run git
Mergetool, which calls a visual merge tool and guides you through solving 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 diagram is as follows:

                               master                                 /C0 ---- C1 ---- C2 ---- C4 ---- C6                        \       /                        C3 ----C5                                \                              issueFix

Note: The implementation of this merge, because the current master branch points to the Commit (C4) is not the direct ancestor of the branch (issuefix), git has to do some processing. In this example, git uses the end of the two branches (C4 and C5) and their common ancestor (C2) for a simple three-way merge. Create a new snapshot of the result of the three-party merger, and automatically create a Commit (C6) pointing to it)

After exiting the merge tool, git will ask you if the merge is successful. If the answer is yes, it will save the relevant files for you to indicate that the status is resolved. Then you can use git commit to complete the merge submission.

 

[Turn] http://blog.microsuncn.com /? P = 2000

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.