Life is not as good as ten, and merging branches is often not smooth sailing.
prepare a new feature1
Branch, continue our new branch development:
git checkout -b feature1
switched to a new branch
' Feature1 '
Modify Readme.txt the last line, instead:
Creating a
New branch is quick
and simple.
in the feature1
Submit on Branch:
$ git add readme.txt
$ git
Commit" and Simple"
the and Simple
111 deletion (-)
Switch to master
Branch:
$ git checkout master
Switched to branch ‘master‘
Your branch is ahead of ‘origin/master‘ by 1
Commit .
Git It will also automatically prompt us for the current master
the branch is larger than the remote master
Branch to advance 1 a commit.
in the master
Branch on the Readme.txt the last line of the file should read:
Creating a
New branch is quick & simple.
Submit:
git add readme.txt
git commit -m
"& Simple"
[master
- b40
0] & simple
1 file changed,
1 insertion(+),
1 deletion(-)
Now, master
Branches and feature1
Each branch has a new commit, which becomes:
this case, Git cannot execute " Quick Merge " can only attempt to merge their own changes, but this merger can be a conflict, we try:
git merge feature1
Auto-merging readme.txt
CONFLICT (content)
: Merge conflict
inch readme.txt
Automatic merge failed; fix conflicts
And then commit the result.
It's a conflict! Git tells us that there isa conflict with theReadme.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 directly view Readme.txt the content of:
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.
< <<<<<< HEAD
Creating a New Branch is Quick simple .
= ======
Creating a New Branch is Quick and Simple .
> >>>>>> Feature1
Git with <<<<<<<
, =======
, >>>>>>>
to mark the contents of different branches, we modify the following to save:
Creating a
New branch is quick
and simple.
Re-submit:
git add readme.txt
git commit -m
"Conflict Fixed"
[master
59bc1cb] conflict fixed
Now, master
Branches and feature1
The branch becomes the following:
With a parameter git log
you can also see the merge of the branches:
$ git log --graph --pretty=oneline --abbrev-commit
*
59bc1cb conflict fixed
|\
| *
the a857c
and simple
* |
400b400 & simple
|/
* fec145a branch test
...
Finally, delete feature1
Branch:
git branch -d feature1
Deleted branch feature1 (was
thea857c).
Work done.
Summary
when Git when a branch cannot be merged automatically, the conflict must be resolved first. After resolving the conflict, submit again, and the merge is complete.
with git log --graph
command to see the branching merge diagram.
git12--Resolving conflicts