Cherry-pick 特定提交作为单个提交

Cherry-pick specific commits as single commit

这是

的跟进问题

我想为代码审查创建一个孤立分支。这个孤立分支将从 SHA_of_first_commit~1 生成,提交消息包含我的 trackingID。创建孤立分支后,我挑选那些包含我的 trackingID 的消息的提交。问题是所有精心挑选的提交都单独显示在孤立分支中。我希望所有这些都被视为一次提交,以便我可以使用这个新的 SHA 检查代码。以下是我现在使用的脚本。

#!/bin/bash

if [ -z  ]; then
    echo "Rationale: Cherry pick all commits in master, that match the tracking ID and create a new branch.";
    echo "";
    echo "Usage:  [=10=] traackingID";
    echo "";
    exit 1;
fi

#If  doesn't match a AGW-<number> pattern, thrown an error

user="$(id -u -n)" > /dev/null

echo "You are - $user"

branchname=$user"_""_review"

echo "Creating branch - $branchname"

basecommit="$(git log master --pretty=oneline --reverse | grep "" | head -1 | cut -d ' ' -f 1)""~1"

echo "Checking out from $basecommit"

git checkout --orphan $branchname $basecommit > /dev/null
git commit -m ""

git rev-list master --reverse --grep="" | while read rev
do
  echo $rev
  git cherry-pick $rev > /dev/null
done

#git push &> /dev/null

echo "Created branch, cherry picked, pushed to remote. Now switching back to master. Bye."

git checkout master

老实说,我看不出签出孤立分支并重新应用一系列提交以进行代码审查有什么意义。但这不是问题。

git cherry-pick 接受 -n (--no-commit) 选项。从文档中,强调我的。

Usually the command automatically creates a sequence of commits. This flag applies the changes necessary to cherry-pick each named commit to your working tree and the index, without making any commit.

cherry-pick 应用有问题的更改后,您可以通过简单的 git commit.

来完成该过程