国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 服務器 > Web服務器 > 正文

bug分支和feature分支_動力節點Java學院整理

2024-09-01 13:52:45
字體:
來源:轉載
供稿:網友

軟件開發中,bug就像家常便飯一樣。有了bug就需要修復,在Git中,由于分支是如此的強大,所以,每個bug都可以通過一個新的臨時分支來修復,修復后,合并分支,然后將臨時分支刪除。

當你接到一個修復一個代號101的bug的任務時,很自然地,你想創建一個分支issue-101來修復它,但是,等等,當前正在dev上進行的工作還沒有提交:

$ git status# On branch dev# Changes to be committed:#  (use "git reset HEAD <file>..." to unstage)##    new file:  hello.py## Changes not staged for commit:#  (use "git add <file>..." to update what will be committed)#  (use "git checkout -- <file>..." to discard changes in working directory)##    modified:  readme.txt#

并不是你不想提交,而是工作只進行到一半,還沒法提交,預計完成還需1天時間。但是,必須在兩個小時內修復該bug,怎么辦?

幸好,Git還提供了一個stash功能,可以把當前工作現場“儲藏”起來,等以后恢復現場后繼續工作:

$ git stashSaved working directory and index state WIP on dev: 6224937 add mergeHEAD is now at 6224937 add merge

現在,用git status查看工作區,就是干凈的(除非有沒有被Git管理的文件),因此可以放心地創建分支來修復bug。

首先確定要在哪個分支上修復bug,假定需要在master分支上修復,就從master創建臨時分支:

$ git checkout masterSwitched to branch 'master'Your branch is ahead of 'origin/master' by 6 commits.$ git checkout -b issue-101Switched to a new branch 'issue-101'

現在修復bug,需要把“Git is free software ...”改為“Git is a free software ...”,然后提交:

$ git add readme.txt $ git commit -m "fix bug 101"[issue-101 cc17032] fix bug 101 1 file changed, 1 insertion(+), 1 deletion(-)

修復完成后,切換到master分支,并完成合并,最后刪除issue-101分支:

$ git checkout masterSwitched to branch 'master'Your branch is ahead of 'origin/master' by 2 commits.$ git merge --no-ff -m "merged bug fix 101" issue-101Merge made by the 'recursive' strategy. readme.txt |  2 +- 1 file changed, 1 insertion(+), 1 deletion(-)$ git branch -d issue-101Deleted branch issue-101 (was cc17032).

太棒了,原計劃兩個小時的bug修復只花了5分鐘!現在,是時候接著回到dev分支干活了!

$ git checkout devSwitched to branch 'dev'$ git status# On branch devnothing to commit (working directory clean)

工作區是干凈的,剛才的工作現場存到哪去了?用git stash list命令看看:

$ git stash liststash@{0}: WIP on dev: 6224937 add merge

工作現場還在,Git把stash內容存在某個地方了,但是需要恢復一下,有兩個辦法:

一是用git stash apply恢復,但是恢復后,stash內容并不刪除,你需要用git stash drop來刪除;

另一種方式是用git stash pop,恢復的同時把stash內容也刪了:

$ git stash pop# On branch dev# Changes to be committed:#  (use "git reset HEAD <file>..." to unstage)##    new file:  hello.py## Changes not staged for commit:#  (use "git add <file>..." to update what will be committed)#  (use "git checkout -- <file>..." to discard changes in working directory)##    modified:  readme.txt#Dropped refs/stash@{0} (f624f8e5f082f2df2bed8a4e09c12fd2943bdd40)

再用git stash list查看,就看不到任何stash內容了:

$ git stash list

你可以多次stash,恢復的時候,先用git stash list查看,然后恢復指定的stash,用命令:

$ git stash apply stash@{0}

Feature分支

軟件開發中,總有無窮無盡的新的功能要不斷添加進來。

添加一個新功能時,你肯定不希望因為一些實驗性質的代碼,把主分支搞亂了,所以,每添加一個新功能,最好新建一個feature分支,在上面開發,完成后,合并,最后,刪除該feature分支。

現在,你終于接到了一個新任務:開發代號為Vulcan的新功能,該功能計劃用于下一代星際飛船。

于是準備開發:

$ git checkout -b feature-vulcanSwitched to a new branch 'feature-vulcan'

5分鐘后,開發完畢:

$ git add vulcan.py$ git status# On branch feature-vulcan# Changes to be committed:#  (use "git reset HEAD <file>..." to unstage)##    new file:  vulcan.py#$ git commit -m "add feature vulcan"[feature-vulcan 756d4af] add feature vulcan 1 file changed, 2 insertions(+) create mode 100644 vulcan.py

切回dev,準備合并:

$ git checkout dev

一切順利的話,feature分支和bug分支是類似的,合并,然后刪除。

但是,就在此時,接到上級命令,因經費不足,新功能必須取消!

雖然白干了,但是這個分支還是必須就地銷毀:

$ git branch -d feature-vulcanerror: The branch 'feature-vulcan' is not fully merged.If you are sure you want to delete it, run 'git branch -D feature-vulcan'.

銷毀失敗。Git友情提醒,feature-vulcan分支還沒有被合并,如果刪除,將丟失掉修改,如果要強行刪除,需要使用命令git branch -D feature-vulcan。

現在我們強行刪除:

$ git branch -D feature-vulcanDeleted branch feature-vulcan (was 756d4af).

終于刪除成功!

 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 福建省| 绥宁县| 资源县| 虹口区| 南投县| 新田县| 松阳县| 临湘市| 昌吉市| 济宁市| 红原县| 若羌县| 唐山市| 平定县| 赤峰市| 万全县| 民丰县| 湟源县| 巨鹿县| 南阳市| 抚宁县| 夏津县| 西安市| 宁阳县| 铁岭市| 元谋县| 武安市| 怀安县| 盘锦市| 宜兴市| 长葛市| 苍山县| 永新县| 韶关市| 十堰市| 房产| 宜丰县| 格尔木市| 保康县| 来宾市| 顺义区|