別のブランチに含まれている最新のコミットを見つけたいです。歴史を考えると
A-B-C---E <-master
└-F---G <-develop
└-H-I <-branch1
Fを見つけたい。私は開始点branch1しか知らず、他のブランチの名前は知らないことに注意してください。
最小のi≥0を簡単にチェックできることを知っています。
git branch --contains branch1~i
複数の行を出力しますが、それは無駄に思えます。
別のブランチに含まれている最新のコミットを見つけたいです。歴史を考えると
A-B-C---E <-master
└-F---G <-develop
└-H-I <-branch1
Fを見つけたい。私は開始点branch1しか知らず、他のブランチの名前は知らないことに注意してください。
最小のi≥0を簡単にチェックできることを知っています。
git branch --contains branch1~i
複数の行を出力しますが、それは無駄に思えます。
これを行うには、Gitディストリビューションに付属しているpost-receive-email/usr/share/doc/git-core/contrib/hooks/post-receive-email
スクリプトを確認してください(ローカルコピーが必要な場合などにインストールする必要があります)。これには、特定のブランチで新しく、他のブランチでは見られなかったコミットのみを見つける方法を説明する長いコメントがあります。
# Consider this:
# 1 --- 2 --- O --- X --- 3 --- 4 --- N
#
# O is $oldrev for $refname
# N is $newrev for $refname
# X is a revision pointed to by some other ref, for which we may
# assume that an email has already been generated.
# In this case we want to issue an email containing only revisions
# 3, 4, and N. Given (almost) by
#
# git rev-list N ^O --not --all
#
# The reason for the "almost", is that the "--not --all" will take
# precedence over the "N", and effectively will translate to
#
# git rev-list N ^O ^X ^N
#
# So, we need to build up the list more carefully. git rev-parse
# will generate a list of revs that may be fed into git rev-list.
# We can get it to make the "--not --all" part and then filter out
# the "^N" with:
#
# git rev-parse --not --all | grep -v N
#
# Then, using the --stdin switch to git rev-list we have effectively
# manufactured
#
# git rev-list N ^O ^X
コメントとスクリプトの残りの部分で、コーナーケースを処理するための詳細があります。しかし、基本的なケースがあなたが気にするすべてであるならば、これはあなたに答えを与えるはずです:
git rev-parse --not --all | grep -v I | git rev-list --stdin I
I
ここで、として計算できます$(git rev-parse branch1)
。結果の最後のエントリはcommitになり、それを使用して別のブランチH
の最新の祖先に到達できます。H^
HIのあるブランチの名前がわかっている場合(例:branch1)
git reflog show --all|grep branch1
称賛の最大数は、そのブランチでの最初のコミットです。