読者です 読者をやめる 読者になる 読者になる

helen's blog

ぽんこつによるぽんこつのためのぽんこつブログ

$ git show-branchって意外と使えるかもしれない

masterをチェックアウトして実行してみた

$ git show-branch
! [aaaaa] Revert "Merge pull request #1 in studygit from develop to master"
 ! [bugfix/revert-merge-commit] Revert "Merge pull request #1 in studygit from develop to master"
  ! [develop] Merge pull request #7 in studygit from feature/fuga to develop
   ! [feature/helen] ゴミコミット
    ! [feature/study-git] untracked branch commit
     * [master] Merge pull request #8 in studygit from release/0420 to master
      ! [real/hoge] testagdhkcl;f
       ! [release/0420] Merge pull request #7 in studygit from feature/fuga to develop
--------
     -   [master] Merge pull request #8 in studygit from release/0420 to master
  -  - - [develop] Merge pull request #7 in studygit from feature/fuga to develop
  -  - - [develop^2] Merge branch 'master' into feature/fuga
  -  - - [master^] Merge pull request #2 in studygit from bugfix/revert-merge-commit to master
+++  * + [aaaaa] Revert "Merge pull request #1 in studygit from develop to master"
  -  - - [master~2] Merge pull request #1 in studygit from develop to master
  -  - - [develop^] Merge pull request #4 in studygit from feature/fuga to develop
  +  * + [develop^2^] feature/fuga this is my first commit
  +  * + [develop~2^2] ふがこみっと
  +  * + [develop~3^2] ごみ.txt コミット
      +  [real/hoge] testagdhkcl;f
    +    [feature/study-git] untracked branch commit
    +    [feature/study-git^] initial commit at feature
   +     [feature/helen] ゴミコミット
+++++*++ [develop~4] initial commit at develop

見方

  • 「---------」より上がローカルブランチ
  • -aで追跡ブランチ、ローカルブランチの両方が見れる
  • *がついてるのが今のブランチ
  • 色がないとわからないけど左側の記号はiTermだと色がついててどのブランチのコミットかわかる

コミットの参照

[feature/study-git^]とか[real/hoge]とか
今のブランチからたどれるコミットとたどり方がわかる

ブランチがどこまでマージされているかを調べる

$ git show-branch branchA branchB

masterとdevelopを比較してどこまでマージされてるか調べれる

ブランチの派生元を調べる

$ git show-branch branchA branchB | tail -1

$ git show-branch master develop
git show-branch master develop
! [master] Merge pull request #8 in studygit from release/0420 to master
 ! [develop] Merge pull request #7 in studygit from feature/fuga to develop
--
-  [master] Merge pull request #8 in studygit from release/0420 to master
-- [develop] Merge pull request #7 in studygit from feature/fuga to develop

一番下の行が派生元
この場合はdevelopが派生元
派生元コミットを参照するときはdevelopで見れる
tail -1で派生元ブランチ、派生元コミットがわかる

参考:Git - git-show-branch Documentation