到目前為止,你已經建立、合併和刪除過分支(branch);讓我們再來看一些分支管理工具,這將會在你開始全程使用分支時派上用場。
git branch 命令不僅能建立和刪除分支,
如果不加任何參數,你將會得到所有分支的簡易清單:
$ git branch
iss53
* master
testing注意 master 分支前面的 * 字元,它表示目前所檢出(checkout)的分支(換句話說,HEAD 指向這個分支);
這意味著如果你現在提交,master 分支將隨之向前移動。
若要查看各個分支最後一個提交,執行 git branch -v:
$ 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 branch --merged 來查看哪些分支已被合併到目前分支:
$ git branch --merged
iss53
* master由於之前的 iss53 已經被合併了,所以會在列表中看到它;
在這個列表中沒有被標記 * 的分支通常都可以用 git branch -d 刪除;你已經把它們的工作內容整併到其他分支,所以刪掉它們也不會有所損失。
查看所有包含未合併工作的分支,可以運行 git branch --no-merged:
$ git branch --no-merged
testing這顯示了你其它的分支;
由於它包含了還未合併的工作,嘗試使用 git branch -d 刪除該分支將會失敗:
$ 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 選項來強制執行,就像上面訊息中所提示的。