2010-06-02 80 views
4

在Git中,(1)給出一個分支和(2)支路B從A在過去的某個點導出,然後合併到A,我怎麼能找到的所有提交現在在一家起源於B'Git:如何查找分支A中所有提交的派生分支B中的所有提交合並回A?

的目的是確定在B現在在A中進行更迅速追查問題的工作的變更。

一個壁球承諾顯然,方便打包整個變更的一個承諾,以供參考,但缺點(如信息和個人attributability損失)使該選項不希望我們。因此我的問題。

回答

5

假設B全面合併爲A,您可以使用:

git cherry -v <merge-commit>^ <topic-branch>

...其中:

  • <merge-commit>^是的父提交,你合併特性分支。
  • <topic-branch>是要檢查
+0

謝謝,Tim。 (抱歉需要一段時間才能回到這一點。)這對我來說非常有效。它需要一個實際的合併提交(「合併由遞歸製造」),這是你所得到的,除非快進已經足夠了,因爲所有的主分支的提交內容已經合併的話題支進前合併到主題分支主分支。 – Lumi 2010-06-05 11:58:14

1

一旦分支已合併回,這次合併提交是其存在的指標。假設你沒有猴子的太多了您的合併提交的信息,你可以做這樣的事情:

#!/bin/bash 

die_with_usage() { 
    # add a git alias for merged-commits to be able to call it like this 
    echo "usage: git merged-commits <branch-merged> <branch-merged-into>" 1>&2 
    exit 1 
} 

if [ $# -ne 2 ]; then 
    die_with_usage 
fi 

# Find the merge commits 
merges=($(git log --pretty=%H --grep="Merge branch '$1' into $2")) 

if [ ${#merges[@]} -eq 0 ]; then 
    echo "error: no such merges found!" 1>&2 
    die_with_usage 
fi 

for merge in ${merges[@]}; do 
    # The first parent is the merged-into branch 
    bar=$merge^1 
    # The second is the merged branch 
    foo=$merge^2 

    # Find the merge base 
    base=$(git merge-base $bar $foo) 

    # Show the commits 
    git log --pretty=%H $base..$foo 
done 

我想這會是有幫助的,只是打印SHA1s,讓你去,並且做你跟他們一樣,但當然你可以擺弄最後的git log的輸出格式。

(!我甚測試,這可能保持它的周圍,它是一個很酷的小几班輪。)

另一件事你可以做(​​在未來)是通過合併沿着混帳的行提交信息.git,它基本上嵌入了合併提交消息中合併提交的短記錄(這裏是an example)。有一個內置的方式做到這一點未來有一天(它被合併到下一個,但沒有掌握),但現在你必須推出自己的,還是做一個大膽的舉動,並從明年建立。

+0

謝謝Jefromi,這也非常有用。它看起來並不總是依賴合併提交消息來包含兩個分支名稱。有時候它只是「合併分支」gurke'「,也許是因爲合併完成了主分支。無論如何,適應模式,你的腳本工作正常。 – Lumi 2010-06-05 12:01:23

1

看看git-resurrect.sh腳本contrib/地區的混帳來源的分支。

 
usage: git resurrect [-a] [-r] [-m] [-t] [-n] [-b <newname>] <name> 

    -b, --branch ...  save branch as instead of <name> 
    -a, --all    same as -l -r -m -t 
    -k, --keep-going  full rev-list scan (instead of first match) 
    -l, --reflog   scan reflog for checkouts (enabled by default) 
    -r, --reflog-merges scan for merges recorded in reflog 
    -m, --merges   scan for merges into other branches (slow) 
    -t, --merge-targets scan for merges of other branches into 
    -n, --dry-run   don't recreate the branch 

git-resurrect attempts to find traces of a branch tip called <name>, 
and tries to resurrect it. Currently, the reflog is searched for checkout 
messages, and with `-r' also merge messages. With `-m' and `-t', the 
history of all refs is scanned for "Merge <name> into other"/
"Merge <other> into <name>" (respectively) in commit subjects, 
which is rather slow but allows you to resurrect other people's 
topic branches. 
+0

謝謝,Jakub。看起來這比我想做的要多一點,但也許這只是我缺乏理解。我用--dry-run來運行它,它提出了一個源於我在命令行上指定的分支的提交列表;但不是所有的人。對我來說,它看起來像是用於更高級的用法。不管怎麼說,還是要謝謝你。 – Lumi 2010-06-05 12:14:45

+0

@Michael:它可能只指定了分支上最重要的將被複活的提交。你可以嘗試'git log $(git-resurrect.sh ... --dry-run)--not '來獲取它們。 – 2010-06-05 12:36:08

+0

它輸出的不僅僅是最上面的提交,然後標記最近的提交。 (我在Cygwin上使用git-1.7.0.4。)現在沒關係,我可能有更多時間在後面深入研究。目前我覺得我還沒有理解一些基礎知識。 – Lumi 2010-06-05 14:02:25

相關問題