簡體   English   中英

如何獲取所有 git 提交到合並分支的列表?

[英]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指向Xinfrelease指向H

master創建release分支后,進行了一系列修復。 其中一些只合並到release (例如BG ),其中一些合並到releasemaster中(例如CD )。 release分支也多次合並回master 在此示例中,我確保所有這些事情都發生了,但實際上它們發生的次數(或更少)可能比我的示例所指示的要多(或更少)。

僅給定關於releasemaster引用的知識,我怎樣才能獲得release分支中所有提交的列表,即AH

我創建了一個帶有上述歷史記錄的示例 repo,以使其更易於測試。

針對X0的一種方法是:

  • 它是最接近的祖先,既是來自主人的始祖鏈,是來自釋放的始祖鏈

我不知道如何在 go 和git rev-listgit 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM