小路有话说:这个先说一下前提,我们在项目中,一般建两个分支,master(主分支)和develop(非主分支),develop分支就是开发人员pull或者push代码的,供日常使用,develop分支代码可以有错误,错误了就修改,当确定develop分支的代码可以正常运行时,我们可以把develop分支上的代码合并到master分支中,master分支轻易不会动,所有想要合并代码就需要一下命令:
假设我们现在在develop分支上,刚开发完项目,执行了下列命令:
git add .
git commit -m '****'
git push -u origin develop
现在想将develop分支合并到master分支,操作如下:
1、首先切换到master分支上
git checkout master
2、如果是多人开发的话 需要把远程master上的代码pull下来
git pull origin master
//如果是自己一个开发就没有必要了,为了保险期间还是pull
3、然后我们把develop分支的代码合并到master上
git merge develop
4、然后查看状态及执行提交命令
git status
On branch master
Your branch is ahead of 'origin/master' by 12 commits.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
//上面的意思就是你有12个commit,需要push到远程master上
> 最后执行下面提交命令
git push origin master
这样我们就可以把代码合并了
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5其他命令
查看所有分支
git branch -a
新建分支
git branch test
切换分支
git checkout test