1. 程式人生 > 其它 >基於功能分支的git工作流

基於功能分支的git工作流

技術標籤:開發工具git版本控制開發

基於功能分支的git工作流

文章目錄


在這裡插入圖片描述

主要思想:所有的功能開發應該在一個專門的分支,而不是在master分支上,這樣可以方便多個開發者在各自的功能上開發而不會弄亂主幹程式碼。

實施步驟

1 新建issue

在倉庫中根據需求,新建一個issue,如標號是1,內容是feature;

2 新建功能分支

名字應該與功能內容聯絡起來,可以以issue的序號和內容連線作為名字,如1-feature

3 在分支上完成修改

提交資訊:第一行概述,空一行,再詳述,

Present-tense summary under 50 characters

  • More information about commit (under 72 characters).
  • More information about commit (under 72 characters).

http://project.management-system.com/ticket/123

4 開發過程注意和master同步

或者不進行,在最後合併時進行,但如果開發週期長,可能與origin差異很大

git fetch origin
git rebase origin/master

5 合併多個commit

分支上commit過多不利於他人閱讀,最好進行合併
可以使用
使用互動模式變基到另一個分支

git rebase -i 036ac

例如

pick 07c5abd Introduce OpenPGP and teach basic usage
pick de9b1eb Fix PostChecker::Post#urls
pick 3e7ee36 Hey kids, stop all the highlighting
pick fa20af3 git interactive rebase, squash, amend

# Rebase 8db7e8b..fa20af3 onto 8db7e8b
# # Commands: # p, pick = use commit # r, reword = use commit, but edit the commit message # e, edit = use commit, but stop for amending # s, squash = use commit, but meld into previous commit # f, fixup = like "squash", but discard this commit's log message # x, exec = run command (the rest of the line) using shell # # These lines can be re-ordered; they are executed from top to bottom. # # If you remove a line here THAT COMMIT WILL BE LOST. # # However, if you remove everything, the rebase will be aborted. # # Note that empty commits are commented out

修改為

pick 07c5abd Introduce OpenPGP and teach basic usage
s de9b1eb Fix PostChecker::Post#urls
s 3e7ee36 Hey kids, stop all the highlighting
pick fa20af3 git interactive rebase, squash, amend

修改後就會變成第一個和第四個兩個commit資訊,第二個和第四個會合併到第一個中,如果不用squash,而是fixup,那麼也會合並,但commit資訊會加上註釋符。

6 提交pull request(github)或merge request(gitlab)

將功能分支推到遠端倉庫

git push origin 1-feature

在git網站上提交一個pr或mr,請求將功能分支合併到master,討論,review,他人在檢視後,決定進行修改或者直接合並。

7 確定後,合併功能分支

git checkout master
git pull
git pull origin 1-feature
git push

8 刪除功能分支

git branch -d 1-feature
# 刪除遠端分支
git push origin -d 1-feature 

參考:

https://www.atlassian.com/git/tutorials/comparing-workflows

http://www.ruanyifeng.com/blog/2015/08/git-use-process.html

https://guides.github.com/introduction/flow/index.html