北京SEO

多master/develop分支如何使用gitflow版本控制

2019/10/10/17:46:33  阅读:1710  来源:谷歌SEO算法  标签: 百度K站

在使用 gitflow 做版本控制系统,发现gitflow的时候只能指定一个master/develop,如果要多分支使用要如何操作呢?那么来看看我是如何给gitflow加料的。

公司都是git作为版本控制,公司一些项目组在用gitflow,但是我们组没有强制,但是我上月出了一次事故,总结就是分支管理问题,所以开始强迫自己使用gitflow,以前的项目是一个master和一个develop,自己checkout一个分支,然后merge(不理解的可以看看a-successful-git-branching-model).

问题出现了:项目有几个主分支和开发分支,比如master_sina,master_qq. master_buzz ,而gitflow的时候只能指定一个master/develop, 这样你start一个feature/hotfix之前就要去.git/config里面修改 [gitflow “branch”]项的相关主分支和开发分支,so不方便,看了下源码,给gitflow加点料.

添加功能

当你打开了feature/hotfix分支,但是你不想要它了(当然你可以直接git branch -D xx),使用git flow hotfix/feature delete,自动帮你删除这个分支,以便你新建其他分支(git flow只容许你一次存在一个hotfix/feature分支).

你想使用gitflow删除其它存在分支嘛?不需要 git branch -D,你还可以git flow hotfix/feature delete XX.

比如我在init的时候指定了master为master_sina,而当我想创建master_qq的hotfix,我只需要在start的是否给它取名字是’qq_‘开头的即可,要是有其它的需要你可以直接在源码里面添加对应的内容.

例子 git-flow-hotfix 我主要标记我修改的部分,代码如下:

  1. init(){
  2. require_git_repo
  3. require_gitflow_initialized
  4. gitflow_load_settings
  5. VERSION_PREFIX=$(eval"echo`gitconfig--getgitflow.prefix.versiontag`")
  6. PREFIX=$(gitconfig--getgitflow.prefix.hotfix)
  7. }
  8. #增加help的选项说明
  9. usage(){
  10. echo"usage:gitflowhotfix[list][-v]"
  11. echo"gitflowhotfixstart[-F]<version>[<base>]"
  12. echo"gitflowhotfixfinish[-Fsumpk]<version>"
  13. echo"gitflowhotfixpublish<version>"
  14. echo"gitflowhotfixdelete[branch]"
  15. echo"gitflowhotfixtrack<version>"
  16. }
  17. cmd_default(){
  18. cmd_list"$@"
  19. }
  20. cmd_list(){
  21. DEFINE_booleanverbosefalse'verbose(more)output'v
  22. parse_args"$@"
  23. localhotfix_branches
  24. localcurrent_branch
  25. localshort_names
  26. hotfix_branches=$(echo"$(git_local_branches)"|grep"^$PREFIX")
  27. if[-z"$hotfix_branches"];then
  28. warn"Nohotfixbranchesexist."
  29. warn""
  30. warn"Youcanstartanewhotfixbranch:"
  31. warn""
  32. warn"gitflowhotfixstart<version>[<base>]"
  33. warn""
  34. exit0
  35. fi
  36. current_branch=$(gitbranch--no-color|grep'^*'|grep-v'nobranch'|sed's/^*//g')
  37. short_names=$(echo"$hotfix_branches"|sed"s^$PREFIXg")
  38. #determinecolumnwidthfirst
  39. localwidth=0
  40. localbranch
  41. forbranchin$short_names;do
  42. locallen=${#branch}
  43. width=$(max$width$len)
  44. done
  45. width=$(($width+3))
  46. localbranch
  47. forbranchin$short_names;do
  48. localfullname=$PREFIX$branch
  49. localbase=$(gitmerge-base"$fullname""$MASTER_BRANCH")
  50. localmaster_sha=$(gitrev-parse"$MASTER_BRANCH")
  51. localbranch_sha=$(gitrev-parse"$fullname")
  52. if["$fullname"="$current_branch"];then
  53. printf"*"
  54. else
  55. printf""
  56. fi
  57. ifflagverbose;then
  58. printf"%-${width}s""$branch"
  59. if["$branch_sha"="$master_sha"];then
  60. printf"(nocommitsyet)"
  61. else--phpfensi.com
  62. localtagname=$(gitname-rev--tags--no-undefined--name-only"$base")
  63. localnicename
  64. if["$tagname"!=""];then
  65. nicename=$tagname
  66. else
  67. nicename=$(gitrev-parse--short"$base")
  68. fi
  69. printf"(basedon$nicename)"
  70. fi
  71. else
  72. printf"%s""$branch"
  73. fi
  74. echo
  75. done
  76. }
  77. cmd_help(){
  78. usage
  79. exit0
  80. }
  81. parse_args(){
  82. #parseoptions
  83. FLAGS"$@"||exit$?
  84. evalset--"${FLAGS_ARGV}"
  85. #readargumentsintoglobalvariables
  86. VERSION=$1
  87. BRANCH=$PREFIX$VERSION

这里就是我多master/develop的技巧,我这里会判断要新建的分支的前缀,要是qq_开头就会基于master_qq和develop_qq创建分支,所以你可以根据你的需要在这里加一些方法.

  1. test`exprmatch"$@""qq_"`-ne0&&MASTER_BRANCH="$MASTER_BRANCH"_qq&&
  2. DEVELOP_BRANCH="$DEVELOP_BRANCH"_qq
  3. }
  4. require_version_arg(){
  5. if["$VERSION"=""];then
  6. warn"Missingargument<version>"
  7. usage
  8. exit1
  9. fi
  10. }
  11. require_base_is_on_master(){
  12. if!gitbranch--no-color--contains"$BASE"2>/dev/null
  13. |sed's/[*]//g'
  14. |grep-q"^$MASTER_BRANCH$";then
  15. die"fatal:Givenbase'$BASE'isnotavalidcommiton'$MASTER_BRANCH'."
  16. fi
  17. }
  18. require_no_existing_hotfix_branches(){
  19. localhotfix_branches=$(echo"$(git_local_branches)"|grep"^$PREFIX")
  20. localfirst_branch=$(echo${hotfix_branches}|head-n1)
  21. first_branch=${first_branch#$PREFIX}
  22. [-z"$hotfix_branches"]||
  23. die"Thereisanexistinghotfixbranch($first_branch).Finishthatonefirst."
  24. }
  25. #添加delete参数,函数需要cmd_开头
  26. cmd_delete(){
  27. if["$1"=""];then
  28. #当不指定参数自动去找存在的未关闭的gitflow分支
  29. localhotfix_branches=$(echo"$(git_local_branches)"|grep"^$PREFIX")
  30. test"$hotfix_branches"=""&&die"Therehasnotexistinghotfixbranchcandelete"&&exit1
  31. else
  32. #指定参数先判断参数是不是的数量格式
  33. test$#!=1&&die"Thereonlyneedoneparameterindicatesthebranchtobedeleted"&&exit1
  34. hotfix_branches="$1"
  35. fi
  36. #当要删除的分支就是当前分支,先checkout到develop分支
  37. test"$hotfix_branches"="$(git_current_branch)"&&echo'Firstcheckoutdevelpbranch';git_docheckout"$DEVELOP_BRANCH"
  38. gitbranch-D${hotfix_branches}>/dev/null2>&1&&echo'DeleteSuccessed'||die"Didnotfindbranch:[$hotfix_branches]"
  39. }
  40. cmd_start(){
  41. DEFINE_booleanfetchfalse"fetchfrom$ORIGINbeforeperformingfinish"F
  42. parse_args"$@"
  43. BASE=${2:-$MASTER_BRANCH}
  44. require_version_arg
  45. require_base_is_on_master
  46. require_no_existing_hotfix_branches
  47. #sanitychecks
  48. require_clean_working_tree
  49. require_branch_absent"$BRANCH"
  50. require_tag_absent"$VERSION_PREFIX$VERSION"
  51. ifflagfetch;then
  52. git_dofetch-q"$ORIGIN""$MASTER_BRANCH"
  53. fi
  54. ifhas"$ORIGIN/$MASTER_BRANCH"$(git_remote_branches);then
  55. require_branches_equal"$MASTER_BRANCH""$ORIGIN/$MASTER_BRANCH"
  56. fi
  57. #createbranch
  58. git_docheckout-b"$BRANCH""$BASE"
  59. echo
  60. echo"Summaryofactions:"
  61. echo"-Anewbranch'$BRANCH'wascreated,basedon'$BASE'"
  62. echo"-Youarenowonbranch'$BRANCH'"
  63. echo
  64. echo"Follow-upactions:"
  65. echo"-Bumptheversionnumbernow!"
  66. echo"-Startcommittingyourhotfixes"
  67. echo"-Whendone,run:"
  68. echo
  69. echo"gitflowhotfixfinish'$VERSION'"
  70. echo
  71. }
  72. cmd_publish(){
  73. parse_args"$@"
  74. require_version_arg
  75. #sanitychecks
  76. require_clean_working_tree
  77. require_branch"$BRANCH"
  78. git_dofetch-q"$ORIGIN"
  79. require_branch_absent"$ORIGIN/$BRANCH"
  80. #createremotebranch
  81. git_dopush"$ORIGIN""$BRANCH:refs/heads/$BRANCH"
  82. git_dofetch-q"$ORIGIN"
  83. #configureremotetracking
  84. gitconfig"branch.$BRANCH.remote""$ORIGIN"
  85. gitconfig"branch.$BRANCH.merge""refs/heads/$BRANCH"
  86. git_docheckout"$BRANCH"
  87. echo
  88. echo"Summaryofactions:"
  89. echo"-Anewremotebranch'$BRANCH'wascreated"
  90. echo"-Thelocalbranch'$BRANCH'wasconfiguredtotracktheremotebranch"
  91. echo"-Youarenowonbranch'$BRANCH'"
  92. echo
  93. }
  94. cmd_track(){
  95. parse_args"$@"
  96. require_version_arg
  97. #sanitychecks
  98. require_clean_working_tree
  99. require_branch_absent"$BRANCH"
  100. git_dofetch-q"$ORIGIN"
  101. require_branch"$ORIGIN/$BRANCH"
  102. #createtrackingbranch
  103. git_docheckout-b"$BRANCH""$ORIGIN/$BRANCH"
  104. echo
  105. echo"Summaryofactions:"
  106. echo"-Anewremotetrackingbranch'$BRANCH'wascreated"
  107. echo"-Youarenowonbranch'$BRANCH'"
  108. echo
  109. }
  110. cmd_finish(){
  111. DEFINE_booleanfetchfalse"fetchfrom$ORIGINbeforeperformingfinish"F
  112. DEFINE_booleansignfalse"signthereleasetagcryptographically"s
  113. DEFINE_stringsigningkey"""usethegivenGPG-keyforthedigitalsignature(implies-s)"u
  114. DEFINE_stringmessage"""usethegiventagmessage"m
  115. DEFINE_stringmessagefile"""usethecontentsofthegivenfileastagmessage"f
  116. DEFINE_booleanpushfalse"pushto$ORIGINafterperformingfinish"p
  117. DEFINE_booleankeepfalse"keepbranchafterperformingfinish"k
  118. DEFINE_booleannotagfalse"don'ttagthisrelease"n
  119. parse_args"$@"
  120. require_version_arg
  121. #handleflagsthatimplyotherflags
  122. if["$FLAGS_signingkey"!=""];then
  123. FLAGS_sign=$FLAGS_TRUE
  124. fi
  125. #sanitychecks
  126. require_branch"$BRANCH"
  127. require_clean_working_tree
  128. ifflagfetch;then
  129. git_dofetch-q"$ORIGIN""$MASTER_BRANCH"||
  130. die"Couldnotfetch$MASTER_BRANCHfrom$ORIGIN."
  131. git_dofetch-q"$ORIGIN""$DEVELOP_BRANCH"||
  132. die"Couldnotfetch$DEVELOP_BRANCHfrom$ORIGIN."
  133. fi
  134. ifhas"$ORIGIN/$MASTER_BRANCH"$(git_remote_branches);then
  135. require_branches_equal"$MASTER_BRANCH""$ORIGIN/$MASTER_BRANCH"
  136. fi
  137. ifhas"$ORIGIN/$DEVELOP_BRANCH"$(git_remote_branches);then
  138. require_branches_equal"$DEVELOP_BRANCH""$ORIGIN/$DEVELOP_BRANCH"
  139. fi
  140. #trytomergeintomaster
  141. #incaseapreviousattempttofinishthisreleasebranchhasfailed,
  142. #butthemergeintomasterwassuccessful,weskipitnow
  143. if!git_is_branch_merged_into"$BRANCH""$MASTER_BRANCH";then
  144. git_docheckout"$MASTER_BRANCH"||
  145. die"Couldnotcheckout$MASTER_BRANCH."
  146. git_domerge--no-ff"$BRANCH"||
  147. die"Thereweremergeconflicts."
  148. #TODO:Whatdowedonow?
  149. fi
  150. ifnoflagnotag;then
  151. #trytotagtherelease
  152. #incaseapreviousattempttofinishthisreleasebranchhasfailed,
  153. #butthetagwassetsuccessful,weskipitnow
  154. localtagname=$VERSION_PREFIX$VERSION
  155. if!git_tag_exists"$tagname";then
  156. localopts="-a"
  157. flagsign&&opts="$opts-s"
  158. ["$FLAGS_signingkey"!=""]&&opts="$opts-u'$FLAGS_signingkey'"
  159. ["$FLAGS_message"!=""]&&opts="$opts-m'$FLAGS_message'"
  160. ["$FLAGS_messagefile"!=""]&&opts="$opts-F'$FLAGS_messagefile'"
  161. evalgit_dotag$opts"$VERSION_PREFIX$VERSION""$BRANCH"||
  162. die"Taggingfailed.Pleaserunfinishagaintoretry."
  163. fi
  164. fi
  165. #trytomergeintodevelop
  166. #incaseapreviousattempttofinishthisreleasebranchhasfailed,
  167. #butthemergeintodevelopwassuccessful,weskipitnow
  168. if!git_is_branch_merged_into"$BRANCH""$DEVELOP_BRANCH";then
  169. git_docheckout"$DEVELOP_BRANCH"||
  170. die"Couldnotcheckout$DEVELOP_BRANCH."
  171. #TODO:Actually,accountingfor'gitdescribe'pays,soweshould
  172. #ideallygitmerge--no-ff$tagnamehere,instead!
  173. git_domerge--no-ff"$BRANCH"||
  174. die"Thereweremergeconflicts."
  175. #TODO:Whatdowedonow?
  176. fi
  177. #deletebranch
  178. ifnoflagkeep;then
  179. #这个问题很奇怪,在完成分支删除它也会存在当前分支是
  180. #要删除的分支删除报错的问题,所以先切换走
  181. test"$BRANCH"="$(git_current_branch)"&&git_docheckout"$DEVELOP_BRANCH"
  182. git_dobranch-d"$BRANCH"
  183. fi
  184. ifflagpush;then
  185. git_dopush"$ORIGIN""$DEVELOP_BRANCH"||
  186. die"Couldnotpushto$DEVELOP_BRANCHfrom$ORIGIN."
  187. git_dopush"$ORIGIN""$MASTER_BRANCH"||
  188. die"Couldnotpushto$MASTER_BRANCHfrom$ORIGIN."
  189. ifnoflagnotag;then
  190. git_dopush--tags"$ORIGIN"||
  191. die"Couldnotpushtagsto$ORIGIN."
  192. fi
  193. fi
  194. echo
  195. echo"Summaryofactions:"
  196. echo"-Latestobjectshavebeenfetchedfrom'$ORIGIN'"
  197. echo"-Hotfixbranchhasbeenmergedinto'$MASTER_BRANCH'"
  198. ifnoflagnotag;then
  199. echo"-Thehotfixwastagged'$VERSION_PREFIX$VERSION'"
  200. fi
  201. echo"-Hotfixbranchhasbeenback-mergedinto'$DEVELOP_BRANCH'"
  202. ifflagkeep;then
  203. echo"-Hotfixbranch'$BRANCH'isstillavailable"
  204. else
  205. echo"-Hotfixbranch'$BRANCH'hasbeendeleted"
  206. fi
  207. ifflagpush;then
  208. echo"-'$DEVELOP_BRANCH','$MASTER_BRANCH'andtagshavebeenpushedto'$ORIGIN'"
  209. fi
  210. echo
  211. }

广告内容

多master/develop分支如何使用gitflow版本控制 多master/develop分支如何使用gitflow版本控制 多master/develop分支如何使用gitflow版本控制

相关阅读

热门评论

小明SEO博客 小明SEO博客

小明SEO博客,新时代SEO博客

总篇数171

精选文章

RMAN中catalog和nocatalog区别介绍 小技巧:为Linux下的文件分配多个权限 zimbra8.5.1安装第三方签名ssl证书的步骤 解决mysql不能远程连接数据库方法 windows服务器mysql增量备份批处理数据库 mysql中slow query log慢日志查询分析 JavaScript跨域问题总结 Linux下负载均衡软件LVS配置(VS/DR)教程 mysql中权限参数说明 MYSQL(错误1053)无法正常启动

SEO最新算法