<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # Bug分支 軟件開發中,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 stash Saved working directory and index state WIP on dev: 6224937 add merge HEAD is now at 6224937 add merge ``` 現在,用`git status`查看工作區,就是干凈的(除非有沒有被Git管理的文件),因此可以放心地創建分支來修復bug。 首先確定要在哪個分支上修復bug,假定需要在`master`分支上修復,就從`master`創建臨時分支: ``` $ git checkout master Switched to branch 'master' Your branch is ahead of 'origin/master' by 6 commits. $ git checkout -b issue-101 Switched 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 master Switched to branch 'master' Your branch is ahead of 'origin/master' by 2 commits. $ git merge --no-ff -m "merged bug fix 101" issue-101 Merge made by the 'recursive' strategy. readme.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) $ git branch -d issue-101 Deleted branch issue-101 (was cc17032). ``` 太棒了,原計劃兩個小時的bug修復只花了5分鐘!現在,是時候接著回到`dev`分支干活了! ``` $ git checkout dev Switched to branch 'dev' $ git status # On branch dev nothing to commit (working directory clean) ``` 工作區是干凈的,剛才的工作現場存到哪去了?用`git stash list`命令看看: ``` $ git stash list stash@{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} ``` http://michaelliao.gitcafe.io/video/stash-fix-bug.mp4 ## 小結 修復bug時,我們會通過創建新的bug分支進行修復,然后合并,最后刪除; 當手頭工作沒有完成時,先把工作現場`git stash`一下,然后去修復bug,修復后,再`git stash pop`,回到工作現場。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看