git多分支 使用小技巧

背景

使用版本管理器进行版本的分支管理的你是否会遇到如下情况:
在同一个项目下,开发的功能,优化的需求,修复的bug多的时候,这些相关代码会分在不同的分支进行管理(功能分支fun,测试分支test,修复分支fixbug,优化opt等)---->某段时间内本地分支也会比较多;@_@
再加上功能以及优化相关的代码还不如bug修复一样需要立即上线---->分支和代码一样会被积压,管理困难以及耗时;QAQ
当时间一久--->上线的,不上线的;该删除的,不该删除的分支就傻傻分不清楚了;{{{(>_<)}}}

so本帅这里根据最近面临的这种情况,对且仅对git做了整理,希望可以小小帮助广大深陷git分支管理的程序猿/媛稍稍摆脱这困境,以便更爽地使用git分支策略!(^_^)

分支管理ing

说明

test-name 用于测试的分支
fun-name 用于开发功能的分支
fix-name、fixbug-name bug修复分支
opt-name 优化分支
name 随便起名字
dev 用于预发布的分支
master 稳定上线的分支

超级多的分支(dev为当前所在分支)-- 谁该删、谁不能删?哪个分支对应哪个代码?下次上线需要合并哪几个分支?

PS D:\shuaipanCompanyData\git\t8t-prs-pqm> git branch
* dev
fun-dataMigration
fun-enquiryOrder
fun-log
fun-node
fun-photos
panshuai
quoteOrder
test-1017

查看最新代码未合并到所在分支(dev分支)的分支

PS D:\shuaipanCompanyData\git\t8t-prs-pqm> git branch --no-merged
fun-log
quoteOrder
test-1017

查看最新代码已经合并到所在分支(dev分支)的分支

PS D:\shuaipanCompanyData\git\t8t-prs-pqm> git branch --merged
* dev
fun-dataMigration
fun-enquiryOrder
fun-node
fun-photos
panshuai

该提交提交、该合并合并、该提交远程提交远程

PS D:\shuaipanCompanyData\git\t8t-prs-pqm> git merge --no-ff fun-dataMigration
Merge made by the 'recursive' strategy.
.../pqm/service/call/MyDecorationOrderService.java | 38 ++++++++++------------
.../service/inner/VerifyAccountInnerService.java | 27 +++++++++++----
2 files changed, 38 insertions(+), 27 deletions(-)
PS D:\shuaipanCompanyData\git\t8t-prs-pqm> git status
On branch dev
Your branch is ahead of 'origin/dev' by 3 commits.
(use "git push" to publish your local commits)

nothing to commit, working directory clean
PS D:\shuaipanCompanyData\git\t8t-prs-pqm> git pull origin dev
From repo.we.com:java/t8t-prs-pqm
* branch dev -> FETCH_HEAD
Already up-to-date.
PS D:\shuaipanCompanyData\git\t8t-prs-pqm> git push origin dev
Counting objects: 121, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (7/7), done.
Writing objects: 100% (12/12), 833 bytes | 0 bytes/s, done.
Total 12 (delta 6), reused 0 (delta 0)
To [email protected]:java/t8t-prs-pqm.git
eb07ff1..688a947 dev -> dev
......
......
......

删除已经合并,并且线上验证ok的分支

PS D:\shuaipanCompanyData\git\t8t-prs-pqm> git branch -d fun-enquiryOrder fun-node fun-photos panshuai
Deleted branch fun-enquiryOrder (was 2208fce).
Deleted branch fun-node (was c20892a).
Deleted branch fun-photos (was 19d02c7).
Deleted branch panshuai (was 4878770).
PS D:\shuaipanCompanyData\git\t8t-prs-pqm> git status
On branch dev
Your branch is up-to-date with 'origin/dev'.

nothing to commit, working directory clean

瞬间干净

PS D:\shuaipanCompanyData\git\t8t-prs-pqm> git branch
* dev
fun-dataMigration
fun-log
quoteOrder
test-1017

你可能感兴趣的:(git多分支 使用小技巧)