git branch
命令不單單能建立和刪除分支,若是不加任何參數,它會給出當前全部分支的清單:javascript
$ git branch iss53 * master testing
注意看 master
分支前的 *
字符:它表示當前所在的分支。也就是說,若是如今提交更新,master
分支將隨着開發進度前移。若要查看各個分支最後一個提交對象的信息,運行 git branch -v
:java
$ git branch -v iss53 93b412c fix javascript issue * master 7a98805 Merge branch 'iss53' testing 782fd34 add scott to the author list in the readmes
要從該清單中篩選出你已經(或還沒有)與當前分支合併的分支,能夠用 --merged
和 --no-merged
選項(Git 1.5.6 以上版本)。好比用 git branch --merged
查看哪些分支已被併入當前分支(譯註:也就是說哪些分支是當前分支的直接上游。):git
$ git branch --merged iss53 * master
以前咱們已經合併了 iss53
,因此在這裏會看到它。通常來講,列表中沒有 *
的分支一般均可以用 git branch -d
來刪掉。緣由很簡單,既然已經把它們所包含的工做整合到了其餘分支,刪掉也不會損失什麼。code
另外能夠用 git branch --no-merged
查看還沒有合併的工做:對象
$ git branch --no-merged testing
它會顯示還未合併進來的分支。因爲這些分支中還包含着還沒有合併進來的工做成果,因此簡單地用 git branch -d
刪除該分支會提示錯誤,由於那樣作會丟失數據:ip
$ git branch -d testing error: The branch 'testing' is not fully merged. If you are sure you want to delete it, run 'git branch -D testing'.
不過,若是你確實想要刪除該分支上的改動,能夠用大寫的刪除選項 -D
強制執行,就像上面提示信息中給出的那樣。開發