21

次の git 履歴があります。

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

安定版からマスター版へのすべての変更を厳選するポリシーがあります。D' と E' は安定版ブランチからチェリー ピックされたコミットであり、F はチェリー ピックではありません (忘れられています)。

F(マスターにチェリーピックされていない)を盛り上げる差分を取得するにはどうすればよいですか?


次の理由により、マージを使用したくありません。

  • マージコミットなしのよりクリーンな履歴
  • 安定版へのコミットはまれです
  • さまざまな安定したブランチがたくさんあります
4

2 に答える 2

18

それがまさにgit cherryコマンドの目的です。

選択されていない変更を見逃すことはありませんが、選択に競合の解決が含まれる場合は、選択されたと見なされる変更がリストされることがあります。

于 2012-02-15T09:40:52.003 に答える
-2

Git コマンドではこれを解決できません。私はこのスクリプトを書きました。

スクリプト 1 番目は、branch1 と branch2 の両方のブランチのマージ ベースを計算します。次に、マージ ベースからブランチ 1 とブランチ 2 のヘッドにそれぞれ 2 つのリストを作成します。次に、コミット メッセージの md5sum を使用して、branch2 にコミットのハッシュ テーブルを作成します。次に、ブランチ 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
于 2017-10-17T05:03:07.930 に答える