git 合作流程
2019-03-05 本文已影响0人
空气KQ
生成密钥
ssh-keygen -t rsa -C "youremail@example.com"
1.配置自己的信息
git config --global user.name "名字"
git config --glboal user.email "邮箱
例如小米,G东,天猫这3个开发者,他们在自己电脑都设置自己的身份
git config --global user.name '小米'
git config --global user.email 'xm@qq.com'
git config --global user.name 'G东'
git config --global user.email 'gd@qq.com'
git config --global user.name '天猫'
git config --global user.email 'tm@qq.com'
2.克隆仓库
服务器端有个建好的仓库
3个开发者都克隆它
git clone git@git.xxx.com:/home/git/store/test.git webstie
3.开发者开发项目
每个人开发者开发前都需要拉取远程的仓库,确保你的分支是最新的
git pull origin master
小米比如完成了添加a.log
touch a.log
它要发布了
添加所有文件到仓库
git add .
这次操作的内容
git commit -m "我添加了a.log"
提交到线上,默认分支只有master
git push origin master
G东来开发了。
G东开发前都需要拉取git pull origin master
touch gd.log
它也要提交
git commit -m "gd.log"
git push origin master
其他人的操作类推。以上是最简单的合作流程
4.开发项目分阶段性合作流程
比如小米收到领导说,你要搞个大模块处理,但是他需要5天时间预算,这个时候也会有小问题处理,怎办?
解决方案:分支创建
它创建了一个dev分支
//创建分支
git checkout -b dev
扩展功能
//切换分支
git checkout dev
//切换主分支
git checkout master
//分支合并
git merge dev
然后在里面进行捣鼓
比如它现在加了个日志表
git add .
git commit -m "add_log_table" //这里一定要先提交,不然你切换还是会给到master
现在领导又叫他这个模块停下,线上的功能改下,怎么办?
切换会主分支,继续开发
git checkout master
然后搞完,提交,
git push origin master
继续切换到dev分支
git checkout dev
....N天过去了,搞完,现在开启合并了。
切换到主分支
git checkout master
合并
git merge dev
如果发生
CONFLICT (content): Merge conflict in a.log
Automatic merge failed; fix conflicts and then commit the result.
说明需要手动合并了。
查看下
<<<<<<< HEAD
123456
=======
789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899
>>>>>>> dev
<<<<<<< HEAD
123456
这个表示属于主分支的,
789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899
>>>>>>> dev
表示属于 dev 分支
2个进行修改
123456789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899789978997899
最后完成。
可参考如下2篇文章
https://www.jianshu.com/p/86728c4625fd
https://www.jianshu.com/p/3a28f8a3f499