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 status
You 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 log
you 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 --graph
you can see the branch merge diagram with the command.
Git tutorials-Resolving conflicts