
使用场景: 项目中同一个服务在2个不同的仓库中开发,当在2中开发的 部分功能 需要合并到1中时。
*** 作步骤:
1)在需要合并的目录打开gitbash,执行
git remote add 远程别名 远程地址
2)git fetch 别名 分支名
此处必须使用 git fetch,因为 git pull = git fetch + git merge,会自动合并所有提交,从而导致不需要的提交被合入当前分支。
3)在gitlab commit查看commit的hash值,或者使用git log查看。复制需要合并的单个或多个hash后,执行命令:
4)使用git status确认状态无误后,执行git push即完成合并
前言:发现新来小伙伴,对git以及repo命令还不是特别熟悉,因此对git及repo最基本命令做了一下小结:
Repo
repo init -u ssh://git@gitlabmanifestgit -b [分支]
repo sync
repo status
repo branch
repo manifest
repo diff
repo help
查看
1 、查看本地分支
git branch
2 、查看远程分支
git branch -r
3 、查看所有分支
git branch -a
4 、查看状态
git status
5 、查看提交日志
git log
创建
本地创建新的分支
git branch [branch name]
切换到新的分支
git checkout [branch name]
创建 + 切换分支
git checkout -b [branch name]
删除
删除本地分支
git branch -d [branch name]
删除 github 远程分支
git push origin :[branch name]
推送
将新分支推送到 github
git push origin [branch name]
提交分支数据到远程服务器
git push origin <local_branch_name>:<remote_branch_name>
例如:
git push origin 20120120806:20120120806
远程分支和本地分支需要区分好,所以,在从服务器上拉取特定分支的时候,需要指定远程分支的名字。
git checkout --track origin/20120120806
注意该命令由于带有--track参数,所以要求git164以上!这样git会自动切换到分支。
分支合并 merge
git merge feature/login
git merge damo_release_201020_feedingRank
tag
git tag 202
git push --tags
1、拉取远端指定的分支(本地不存在)
git fetch
git checkout -b 本地分支名 origin/远程分支名
2、创建本地分支,并推送到远端
(二) 推送本地分支到远程仓库
git push --set-upstream origin 分支名
本地分支推送到远端:
repo forall -c git push ika damo_:damo_
本地分支与远端建立关联跟踪:
repo forall -c git branch --set-upstream-to=module/damo_ damo_
设置本地分支与远程分支的追踪:
git branch --set-upstream-to=origin/远程分支名 本地分支名
基于远端分支创建分支:
1、先fetch 远端的 ila_210120
repo forall -c git fetch ila ila_210120
2、基于远端的ila_210120创建 damo_ila_210120分支
repo forall -c git checkout -b damo_ila_210120 ila/ila_210120
cherry-pick :(某一个 commit )
git cherry-pick f8857cbb08519b10981b0e2df999363ebfe8b6d3
push 推送到远端
git push ila damo_ila_210120_review
强推:
git push --force ila 201140_newGuide_oneCommit
合成一个 commit 流程 :
1、创建一个新分支:
2、reset到第一个commit:
3、重新commit:
reset 区别:
repo forall -c git reset --hard
repo forall -c git reset --soft f8857cbb08519b10981b0e2df999363ebfe8b6d3
1、 >
方法/步骤
首先,项目成员都必须设置为 “Developer”(开发者)
找到分支页面
点击“Protected”栏
选择一个分支,然后点击“Protect”按钮
这样所选分支对于所有 Developer 权限的账号,都无法 push,从而起到保护作用
Git push 命令的陷阱
push 包含了默认 merge *** 作,该过程是自动的,如果有冲突代码段,只是简单的用时间较新的覆盖时间较老的代码,因此,常常会导致代码段丢失,从而破坏分支
以上就是关于Git不同项目代码分支合并,且仅合并特定提交全部的内容,包括:Git不同项目代码分支合并,且仅合并特定提交、Git & Repo 最基本命令 菜鸟教程、怎么从gitlab中克隆分支代码等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)