--- title: Git分支管理-查看分支 date: 2020-11-18 17:43:57 permalink: /pages/a399b3/ categories: - 《Git》学习笔记 tags: - Git author: name: xugaoyi link: https://github.com/xugaoyi --- # Git分支管理-查看分支 ### 查看分支 ```sh $ git branch iss53 * master # 带星号*表示当前所在分支 testing ``` `git branch` 命令不只是可以创建与删除分支。 如果不加任何参数运行它,会得到当前所有分支的一个列表。 ### 查看每个分支的最后提交 ```sh $ git branch -v iss53 93b412c fix javascript issue * master 7a98805 Merge branch 'iss53' testing 782fd34 test ``` ### 查看已(未)合并的分支 `--merged` 与 `--no-merged` 这两个选项可以查看哪些分支已经合并或未合并到 **当前** 分支。 ```sh $ git branch --merged # 查看已合并分支列表 iss53 * master ``` 上面列表中分支名字前没有 `*` 号的分支通常可以使用 `git branch -d` 删除掉; ```sh $ git branch --no-merged # 查看未合并的分支列表 testing ``` 上面显示未合并的分支,尝试使用 `git branch -d` 命令删除它时会失败: ```sh $ 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'. ``` 强制删除未合并的分支: ```sh $ git branch -D testing ``` #### 查看指定分支的已(未)合并的分支 上面描述的选项 `--merged` 和 `--no-merged` 会在没有给定提交或分支名作为参数时, 分别列出已合并或未合并到 **当前** 分支的分支。 你总是可以提供一个附加的参数来查看其它分支的合并状态而不必检出它们。 例如,尚未合并到 `testing` 分支的有哪些? ```sh $ git branch --no-merged testing topicA featureB ```