Introduction to the concept of git merge
The git merge command is used to join (merge) two or more development histories together.
use syntax
git merge [-n] [--stat] [--no-commit] [--squash] [--[no-]edit]
[-s <strategy>] [-X <strategy-option>] [-S[<keyid>]]
[--[no-]allow-unrelated-histories]
[--[no-]rerere-autoupdate] [-m <msg>] [<commit>…]
git merge --abort
git merge --continue
describe
Put the changes from the named commit (after its history has been transferred from the current branch to the current branch). This command is used by git pull to merge changes from another repository and can be used manually to merge changes from one branch to another.
example
Here are some examples
example-1
to merge branches fixes
and enhancements
on top of current branch to make them merged:
$ git merge fixes enhancements
Example-2
To merge obsolete
a branch into the current branch, use ours合并策略
:
$ git merge -s ours obsolete
Example-3
Merge a branch maint
into the current branch, but don't automatically make new commits:
$ git merge --no-commit maint
Use this option when you want to make further changes to the merge, or want to write the merge commit message yourself. This option should not be abused to sneak into merge commits. Small fixes like version names would be acceptable.
Example-4
merges a branch dev
into 当前分支
, automatically making new commits:
$ git merge dev
Branch merge case
git merges the dev branch to the master
If we are now on the dev branch and just finished developing the project, execute the following command
git add .
git commit -m ‘dev'
git push -u origin dev
Then how do we merge the code of the dev branch into the master branch?
First switch to the master branch
git checkout master
If it is developed by multiple people, you need to pull the code on the remote master
git pull origin master
If it is a self-development, it is not necessary, for the insurance period, it is still pull
Then we merge the code of the dev branch into the master
git merge dev
then check status
git status
//意思就是你有12个commit,需要push到远程master上
On branch master
Your branch is ahead of 'origin/master' by 9 commits.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
Just execute the following command
git push origin master