多个协作代码push流程
重点答疑:
-
rebase和merge的区别?
答:merge会生成新的提交点,而rebase不会生成新的提交点,rebase只是剪切一段提交嫁接到master分支;推荐使用rebase而不是merge;
-
rebase 操作时代码冲突怎么处理?
答:冲突时,修改冲突的文件,修改完毕后,通过git add 冲突的文件 后 git rebase --continue 继续 rebase; -
自己的分支上有多个commit,但只想向master提交某个commit修改,不想全部提交怎么办?
答:git cherry-pick 摘取指定的commit id 合并master;
-
想看某个版本的某个文件和当前文件的差异
答:git diff commit_id1 commit_id2 – filename 对比差异点
dom本地开发
test关联的是wangshiwei03
git checkout -b wuxiaoyu_dom
git pull test wuxiaoyu_dom
可选
[git branch --set-upstream-to=test/master wuxiaoyu_dom]
推送到test
git push test wuxiaoyu_dom
推送到origin,先pull
git pull origin wuxiaoyu_dom 【解决冲突】
git push origin wuxiaoyu_dom
git checkout master
git merge wuxiaoyu_dom --ff-only
git push
workflow
不要在master上直接merge自己的分支
在自己分支进行 git checkout master
在master分支上进行 git pull
在master分支上进行 git checkout wuxiaoyu
在自己分支进行 git rebase master
在master分支上进行解决冲突
git diff
git add
在自己分支进行 git rebase —continue
git checkout master
在master分支上进行 git merge wuxiaoyu --ff-only
git push
解决冲突删除了的话,恢复原状执行:git rebase --abort
rebase 介绍:https://www.cnblogs.com/pinefantasy/articles/6287147.html
—ff-only :如果合并过程出现冲突,Git会自动abort此次merge
迁移oceanus操作
-
禁用plus发布项 (灰度模式自动禁用) http://plus.sankuai.com/history.html?release_id=12481
-
创建分支git checkout -b web2oceanus
-
在分支上进行配置修改注释域名配置,新增迁移域名的include 配置到oceanus.conf文件
-
提交分支到远程
-
git add .
-
git commit
-
git push -u origin web2oceanus
-
-
从分支构建用于发布的包,逐步灰度并观察服务,全量 (观察错误日志、迁移的域名日志、defalut server 的日志、网络Load等系统各项指标有无异常)
-
合并分支
-
git checkout master
-
git merge web2oceanus
-
git push
-
-
打开plus禁用的项目 (结束灰度启用)
-
删除本地分支git branch -d web2oceanus
-
回滚操作
-
回滚部署上一版本
-
如何提PR
push到远端,这个时候直接git push会报错,根据提示执行命令git push --set-upstream origin dataapp_search_intelli_fallback
[@wuxiaoyudeMacBook-Pro:nginx-conf (dataapp_search_intelli_fallback)]$ git push
fatal: The current branch dataapp_search_intelli_fallback has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin dataapp_search_intelli_fallback
[@wuxiaoyudeMacBook-Pro:nginx-conf (dataapp_search_intelli_fallback)]$ git push --set-upstream origin dataapp_search_intelli_fallback
Counting objects: 799, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (251/251), done.
Writing objects: 100% (799/799), 196.81 KiB | 0 bytes/s, done.
Total 799 (delta 537), reused 715 (delta 460)
remote:
remote: Create pull request for dataapp_search_intelli_fallback:
remote: http://git.sankuai.com/projects/SA/repos/nginx-conf/compare/commits?sourceBranch=refs/heads/dataapp_search_intelli_fallback
remote:
To ssh://git.sankuai.com/sa/nginx-conf.git
* [new branch] dataapp_search_intelli_fallback -> dataapp_search_intelli_fallback
Branch dataapp_search_intelli_fallback set up to track remote branch dataapp_search_intelli_fallback from origin.
[@wuxiaoyudeMacBook-Pro:nginx-conf (dataapp_search_intelli_fallback)]$
登陆:http://git.sankuai.com/v1/ 右侧选择对应的git库,进入新的界面点击new pr
如下图,选择刚才的分支和远端的master分支,然后点击create pr
填写备注信息和相关的处理人,对方就会收到请求并合并到master分支。
常见报错
1.
最近使用git pull的时候多次碰见下面的情况:
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> release
其实,输出的提示信息说的还是比较明白的。
使用git在本地新建一个分支后,需要做远程分支关联。如果没有关联,git会在下面的操作中提示你显示的添加关联。
关联目的是在执行git pull, git push操作时就不需要指定对应的远程分支,你只要没有显示指定,git pull的时候,就会提示你。
解决方法就是按照提示添加一下呗:
git branch --set-upstream-to=origin/remote_branch your_branch
其中,origin/remote_branch是你本地分支对应的远程分支;your_branch是你当前的本地分支。
2.
我在本地建了一个分支wangxiao,开发完之后,提交代码
git add .
git commit -m '注释'
git push
出现下面的问题,这个意思是:当前分支没有与远程分支关联。
因此导致了提交代码失败。
MacBook-Pro-5:web-crm wangxiao$ git push
fatal: The current branch wangxiao has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin wangxiao
解决方案:
(1)直接 git push origin wangxiao 推向制定的分支,最强暴的方法。
(2)正如上面所说关联远程分支。
git push --set-upstream origin wangxiao
这样关联有一个好处,以后就不用每次git push都用第(1)种方法。

浙公网安备 33010602011771号