LoginSignup
5

More than 3 years have passed since last update.

自分の親ブランチが知りたい

Last updated at Posted at 2020-10-21

自分用の備忘録です:point_up:
間違っている点等ありましたらご指摘ください!!

GUIツールを使っていないので、ふとカレントブランチの親ってなんだっけとなりました。
そこで素晴らしい記事を見つけたので、使ってみました。

☆使いかた

$ git show-branch | grep '*' | grep -v "$(git rev-parse --abbrev-ref HEAD)" | head -1 | awk -F'[]~^[]' '{print $2}'

これだけです!!

現在のブランチを確認して、実際に使ってみました。
もしブランチ名の命名を間違えてプッシュしてしまっても、親ブランチを確認することができます。
素敵ですね。

親ブランチ確認
$ git branch 
  d/ww1
  feature/#0001
* feature/#0002
  staging
  develop
  master
$ git show-branch | grep '*' | grep -v "$(git rev-parse --abbrev-ref HEAD)" | head -1 | awk -F'[]~^[]' '{print $2}'
feature/#0001

☆おまけ

VSCodeでプラグインを入れる前に、よく使っていました。
現在のGitのブランチ状態を確認できます。

現在のツリー確認
$ git log --graph
* commit 12345656e123456s (HEAD -> feature/#0002, origin/feature/#0002)
| Author: hogeta_hogeo <hoge.hoge@hoge.com>
| Date:   Wed Oct 21 09:35:56 2020 +0900
| 
|     xxxxコミットタイトルxxxx
|   
*   commit ss1aas23456df56e1234wesaw56s
|\  Merge: 親コミット1 親コミット2
| | Author: hogeta_hogeo <hoge.hoge@hoge.com>
| | Date:   Wed Oct 21 09:30:50 2020 +0900
| | 
| |     Merge branch 'd/ww1' into feature/#0002
:...skipping...

親ブランチを切り間違えていた時にADDを取り消したいなぁなんてこともあるかと思います!
下記で対応しました。

間違いステージングを取り消し
$ git reset HEAD
Unstaged changes after reset:
M       docker/php/Dockerfile

# 特定のファイルを取り消し
$ git reset HEAD ファイル名

☆参考文献

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5