Git tutorials-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 feature1Switched to a new branch ‘feature1‘

Modify the last line of Readme.txt to read:

new branch is quick AND simple.

Commit on the feature1 branch:

commit -m "AND simple"[feature1 75a857c] AND simple 1 file changed, 1 insertion(+), 1 deletion(-)

Switch to master branch:

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 branch is quick & simple.

Submit:

$ git add readme.txt $ git commit -m "& simple"[master 400b400] & simple 1 file changed, 1 insertion(+), 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 feature1Auto-merging readme.txtCONFLICT (content): Merge conflict 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:

 git is a distributed version control system. Git is free software distributed under the GPL. Git has a mutable index called stage. Git tracks changes of files. <<<<<<<  Headcreating a new branch is quick & simple.=======creating a new branch is span class= "attribute" >quick and simple.>>>>>> > Feature1               

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

new branch is quick and simple.

Re-submit:

$ git add readme.txt $ git commit -m "conflict fixed"[master 59bc1cb] conflict 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...

Now, 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 tutorials-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.