Git-Resolving conflicts

Source: Internet
Author: User

Life is not as good as ten, and merging branches is often not smooth sailing.

Prepare a new feature1 branch and continue our new branch development:

git checkout- b feature1 New ' Feature1 '

Modify the last line of Readme.txt to read:

New  is quick and simple.

Commit on the feature1 branch:

$ git add readme.txt   - M " and Simple"  111 deletion (-)

Switch to master branch:

$ git checkout master  ' Master '  is'origin/master'1 commit.

Git also automatically prompts US master that the current branch is ahead of 1 commits than a remote master branch.

On the master branch, change the last line of the Readme.txt file to:

New  are quick & simple.

Submit:

git add readme.txt $-m "& Simple"&11 1 deletion (-)

Now, the master branches and feature1 branches each have new commits, each of which becomes:

In this case, git cannot perform a "quick merge" and can only attempt to merge its own changes, but the merge may conflict, so let's try this:

git merge Feature1 Auto- in readme.txtautomatic merge failed, fix conflicts and then commit the result.

It's a conflict! Git tells us that there is a conflict with the Readme.txt file and must be resolved manually before committing . git statusYou can also tell us the conflicting files:

 $ git status  # on branch master# Your branch 
    is  ahead of  " origin/master   " by 2   commits.## unmerged paths:# (use   git Add/rm <file>, .....   " as   appropriate to mark Resolution) # # Both modified:readme.txt#no changes added to Commit (use   git add   " and/or "  git commit-a  ")

We can view the contents of Readme.txt directly:

is are free software distributed under the GPL. Git has a mutable index called stage. Git tracks changes of files. <<<<<<<new is quick & simple . =======new is quick and simple . >>>>>>> Feature1

Git uses <<<<<<< , ======= to >>>>>>> mark out the contents of different branches, we modify the following to save:

New  is quick and simple.

Re-submit:

$ git add readme.txt   - M "Conflict fixed"  Fixed

Now, the master branches and feature1 branches become the following:

git logyou can also see the merging of branches with parameters:

git log--graph--pretty=oneline--abbrev-commit*   59BC1CB Conflict fixed| | * 75a857c and simple* | 400b400 & simple|/* fec145a Branch test ...

Finally, delete the feature1 branch:

git branch-  d feature1Deleted branch Feature1 (was 75a857c).

Work done.

Summary

When git cannot merge branches automatically, you must resolve conflicts first. After resolving the conflict, submit again, and the merge is complete.

git log --graphyou can see the branch merge diagram with the command.

Git-Resolving conflicts

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.