LoginSignup
13
8

More than 5 years have passed since last update.

git のあるコミットが、特定のブランチに属するか調べる方法 (のメモ)

Last updated at Posted at 2016-08-09

Git コマンド

$ git branch --contains <commit_id>

を使う。そのコミットが属するブランチを表示してくれます。

たとえば Bash で git コマンドを使って if 分岐をするのであれば

  if [ "$(git branch --contains $commit_id | sed -e 's|[\* ]*||' | grep -E ^$branch_name$)" = "" ]; then
    echo "$branch_name 上のコミットじゃないです"
  fi

こんな感じで判定できます。

上記では、 sed で整形してから、完全一致するものがあるかを grep で調べています。

️ Github API

方法わかったら書こうと思います (できるんですかね...?

13
8
0

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
13
8