Branch merge
Different usage scenarios of branch merge:
- Merge the specified branch to the current branch
- Branch merge conflict
- (Non) Fast-forward mode merge
1. Merge the specified branch to the current branch
Merge the specified branch to the current branch
git merge <branch name>
Two, the conflict of branch merge
When multi-branch collaboration, there will often be some conflicts;
Your local has two branches master/dev
, pointing to the same version, the initial state is the same, and there is only one readme.txt
file.
You master
add a paragraph above hello master
, andadd/git commit
Then switch to dev and add a paragraph hello dev
, andadd/commit
At this point, if you want to merge dev
to master
the branch consolidation occurs conflict
1. Resolve branch merge conflicts
When performing git merge <branch name>
branch merging, if the following conflicts occur, you need to manually merge and then submit;
$ git merge feature1
Auto-merging readme.txt
CONFLICT (content): Merge conflict in readme.txt
Automatic merge failed; fix conflicts and then commit the result.
# when resolve the conflict, can exec the following commands:
# git add <files>
# git commit -m "descibe content"
# this command can show the commit graph.
# git log --graph
3. (Non) Fast-forward mode merger
1. ff mode
When you create a new branch named it dev
, then add a readme.txt
file to this branch, switch to master to do the merge operation, execute:
# To execute merege command on master branch.
git merge dev
If the dev branch is deleted at this time, the branch information will disappear; this merge mode is called Fast-Forward mode
2. --no-ff mode
If the --no-ff
mode is used , it means the mode is disabled ff
, and execute:
# To execute merge command using --no-ff mode on master branch.
git merge --no-ff -m "describe message about this commit" dev