2012-02-15 71 views
18

我有以下git的歷史:git的穩定分支:找不櫻桃採摘提交

A --- B --- C --- D' --- E' [master] 
\ 
    \ --- D --- E --- F [stable] 

我們有一個政策,櫻桃採摘從穩定的所有更改掌握; D'和E'是來自穩定分支的櫻桃採摘承諾,F不是櫻桃採摘(已被遺忘)。

我怎樣才能得到一個F的比較(這是不是櫻桃採摘到主)?


我們不希望使用合併的原因是:

  • 吸塵器歷史不合並提交
  • 承諾穩定是罕見的
  • 我們有很多不同的穩定分支

回答

13

這正是git cherry命令的用途。

它不應該錯過未改變的改變,但它可能偶爾列出你選擇的改變,如果選擇涉及衝突解決。

+0

我希望它有選項--no-合併了Git日誌都有。 – angularsen 2014-06-23 11:05:16

+1

@anjdreas看來櫻桃沒有列出合併提交,與git 2.13.2。 – fossilet 2017-07-06 08:29:14

-2

Git命令無法解決此問題。 我已經寫了這個腳本,它可以幫助。

Script 1st計算兩個分支branch1和branch2的合併基數。 然後它會分別從分支1和分支2的合併基地到頭部創建兩個列表。 然後它在分支2上創建一個提交消息的md5sum的提交散列表。然後它通過分支1的提交列表並檢查分支2哈希表中是否存在?

在上述情況下BRANCH1穩定BRANCH2是主

#!/bin/bash 

## Usage: ./missing_cherrypicks.sh branch1 branch2 
## This script will find commits in branch1 missing in branch2 
## Final list of missing commit will be in file missing_commits_branch1_branch2.csv 

branch1=$1 
branch2=$2 

# Calculate mergebase of branch1 and branch2 
mb=`git merge-base origin/$1 origin/$2` 
rm -rf missing_commits_${branch1}_${branch2}.csv 
echo "COMMIT,AUTHOR,MESSAGE,FILESLIST" >> missing_commits_${branch1}_${branch2}.csv 

# Get commit list on both branches from merge-base 
declare -a commitlist1=`git rev-list $mb..origin/$1` 
declare -a commitlist2=`git rev-list $mb..origin/$2` 

## Make HashKey for branch2 
declare -A CommitHash 
for com2 in ${commitlist2[@]} 
do 
    message2=`git log --pretty=oneline $com2 | head -1| sed "s/${com2} //" | sed 's/ *$//' | cut -c1-35` 
    hashkey=`echo $message2 |md5sum |xargs | awk '{print $1}'` 
    CommitHash[${hashkey}]=$com2 
done 

# Find commits of commitlist1 and check if they are in commitlist2 
for com1 in ${commitlist1[@]} 
do 
    message1=`git log --pretty=oneline $com1 | head -1| sed "s/${com1} //"| sed 's/ *$//'| cut -c1-35` 
    hashkey1=`echo $message1 |md5sum |xargs | awk '{print $1}'` 
    if [[ -z ${CommitHash[${hashkey1}]} ]] 
    then 
     echo "------$com1-----------" 
     author=$(git show $com1 |grep ^Author:|awk -F":" '{print $2}') 
     fileslist=`git diff-tree --no-commit-id --name-only -r $com1` 
     fl="" 
     for file in ${fileslist[@]} 
     do 
      fl=${fl}":"$file 
     done 

     echo "------$author-------" 
     echo "$com1,$author,$message1,$fl" >> missing_commits_${branch1}_${branch2}.csv 
    fi 
done 
+1

請您詳細說明*如何*和*爲什麼*這解決了OP的問題?只是粘貼一些代碼並不是一個好的答案,但它可以在技術上回答這個問題。 – 2017-10-17 05:11:32

+0

Script 1st計算兩個分支branch1和branch2的合併基數。然後分別從分支1和分支2的合併基礎到頭部創建兩個列表。然後它在分支2上創建一個包含消息md5sum的提交散列表。然後它通過分支1的提交列表並檢查分支2哈希表中是否存在。 – 2017-10-17 05:17:39

+0

在上面的例子中,branch1是穩定的,branch2是master。 – 2017-10-17 05:22:22