git stable branch:找不到樱桃选择的提交

时间:2012-02-15 07:59:32

标签: git diff cherry-pick git-diff

我有以下git历史记录:

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

我们有一个政策来挑选从稳定到掌握的所有变化; D'和E'是来自稳定分支的樱桃采摘承诺,F不是樱桃采摘(已被遗忘)。

我怎样才能得到一个将F绑定的差异(这不是被挑选出来的主人)?


我们不希望使用合并,因为:

  • 没有合并提交的清洁历史记录
  • 承诺稳定罕见
  • 我们有很多不同的稳定分支

2 个答案:

答案 0 :(得分:13)

这正是git cherry命令的用途。

它绝对不会错过未经修改的更改,但如果选择涉及冲突解决,它可能会偶尔列出您认为选择的更改。

答案 1 :(得分:-2)

Git命令无法解决此问题。 我写过这个脚本,它可以提供帮助。

Script 1st计算分支branch1和branch2的合并基数。 然后它分别从merge1 base到branch1和branch2的头部创建两个列表。 然后它使用提交消息的md5sum在branch2上创建一个提交哈希表。然后它通过branch1的提交列表并检查branch2哈希表中是否存在?

在上面的例子中,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