13

玩转git-flow工作流-分支解析

 3 years ago
source link: http://developer.51cto.com/art/202102/646222.htm
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

概述

搞开发的相信大部分人git天天都在用,那么一般我们在实际工程当中,遵循一个合理、清晰的Git使用流程,是非常重要的。否则,每个人都提交一堆杂乱无章的commit,项目很快就会变得难以协调和维护。那么是如何来规范整个流程的呢 ;

标准其实很多,这里我们介绍下Gitflow;

什么是Gitflow

Gitflow是基于Git的强大分支能力所构建的一套软件开发工作流,最早由Vincent Driessen在2010年提出。最有名的大概是下面这张图。

图片

那么针对这个规范我们来看下如何在实际使用中来应用整个流程

分支说明

主要分两种 主分支 和 支援性分支

● 主分支 : 分支目录為单层,分支永久保留

○ develop : 当 feature branches 开发完成后,提供测试时,请合并到此,此分支不做任何的程序修改和变更集,只接受 master 和 feature branches 的合并

○ master : 永远处在 production-ready 状态

● 支援性分支 : 分支层级为双层,合并后且沒使用可刪除

○ feature branches : 新功能开发,分支的建立都以 master 為来源

○ hotfix branches : 临时需修改的 bug ,分支的建立都以 master 為來源

○ release branches: 提供 Marketing 测试,预计要上线的版本,分支的建立都以 master 為來源,且在合并要测试的 feature branches,合并完成后请设定 Tag,Tag 的內容為合并的 feature branches

分支的来源和合并

图片

● 主分支

○ develop

■ 来源 : master, feature branches

■ 合并 : 无

○ master

■ 来源 : 无

■ 合并 : release branches, develop

● 支援性分支 : 分支层级為双层

○ feature branches

■ 来源 : master

■ 合并 : release branches, develop

○ hotfix branches

■ 来源 : master

■ 合并 : release branches, develop, master

○ release branches

■ 来源 : master, feature branches

■ 合并 : master

支援性分支命名

● feature branches : 依功能命名

○ ex: 开发的新功能为 FeedbackDashboard,请命名为 feature/FeedbackDashboard

● hotfix branches : 依修改的 bug 命名

○ ex: 修改 Invoice 的显示错误,请命名为 hotfix/Invoice

● release branches : 因為合并多个 feature branch,需依日期命名

○ ex: release/20171013

分支对应环境

● 主分支

○ develop : 开发环境

○ master : 生产环境

● 支援性分支

○ feature branches : 无

○ hotfix branches : 无

○ release branches : 沙箱环境

Git 常用指令

请安裝 Git Windows : https://git-scm.com/download/win

● 分支合并

○ git merge feature/xxx --no-ff

○ :ws!

● 同步远端分支

○ git remote update

○ git remote update origin --prune

● 加入 dll 到 Git

○ git add xxx.dll -f

● 还原本机所有变更集

○ git reset --hard HEAD~

● 建立 Tag

○ git tag -a tagName

● 同步 Tag 到远端

○ git push origin tagName

● 查询 Tag 的內容

○ git show tagName

● 刪除 Tag

○ git push -d origin tagname

○ git -d tagname


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK