[英]How do I get a list of all git commits to a merged branch?
我有一個與這個非常相似的問題,但我不知道如何將解決方案應用於我的案例,因為我的案例稍微復雜一些。
考慮以下歷史:
X0 - X1 - - X - X - Xn - ... - Xinf
\ / / /
\ C - D / /
\ / \ / /
A - E - F - H
\ / \ /
B G
master
指向Xinf
, release
指向H
。
從master
創建release
分支后,進行了一系列修復。 其中一些只合並到release
(例如B
和G
),其中一些合並到release
和master
中(例如CD
)。 release
分支也多次合並回master
。 在此示例中,我確保所有這些事情都發生了,但實際上它們發生的次數(或更少)可能比我的示例所指示的要多(或更少)。
僅給定關於release
和master
引用的知識,我怎樣才能獲得release
分支中所有提交的列表,即A
到H
?
我創建了一個帶有上述歷史記錄的示例 repo,以使其更易於測試。
針對X0
的一種方法是:
我不知道如何在 go 和git rev-list
或git log
中單獨使用它,但這是一種通過腳本獲取它的方法:
# get the list of first-parents of master, store this list in a file :
$ git rev-list --first-parent master > /tmp/tmp-rev-list
# get the list for release, and grep it using 'tmp-rev-list'
# commits will be listed in topo order, 'X0' is the first one :
$ git rev-list --first-parent release | grep -f /tmp/tmp-rev-list | head -1
您可以使用-F
加速grep
(意思是:所有模式都是鈍字符串,沒有正則表達式),
您可以使用<(... )
跳過 tmp 文件:
$ X0=$( git rev-list --first-parent release |\
grep -Ff <(git rev-list --first-parent master) |\
head -1 )
# obviously : it would be better to write this command in a script,
# and then use it to get X0: X0=$(bash myscript.sh)
一旦你有了這個提交 ID,你就可以運行:
$ git log $X0..release
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.