我有以下git历史记录:
A --- B --- C --- D' --- E' [master]
\
\ --- D --- E --- F [stable]
我们有一个政策,从稳定到主控的所有变化都是樱桃挑选的;D‘和E’是从稳定分支中樱桃挑选的提交,F不是樱桃挑选的(已经被遗忘)。
我怎样才能得到一个把F(不是精心挑选的)放入master中的diff呢?
我们不想使用merge,因为:
没有合并commits
发布于 2012-02-15 17:40:52
这正是git cherry
命令的作用所在。
它永远不应该错过未选择的更改,但如果选择涉及冲突解决,它可能会偶尔列出您认为已选择的更改。
发布于 2017-10-17 13:03:08
Git命令无法解决此问题。我已经写了这个脚本,它可以帮助你。
脚本1计算分支branch1和branch2的合并基数。然后,从合并基址到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
https://stackoverflow.com/questions/9289731
复制相似问题