This is a follow up question for Git cherry pick those commits that contain a keyword (tracking id)
I want to create an orphan branch for code reviews. This orphan branch will be made from the SHA_of_first_commit~1 with commit messages that contain my trackingID. After the orphan branch is created, I cherry-pick those commits with messages that contain my trackingID. The problem is all the cherry-picked commits are shown individually in the orphan branch. I want to all of them to be seen as a single commit so that I can review the code with this new SHA. Following is the script I use now.
#!/bin/bash
if [ -z $1 ]; then
echo "Rationale: Cherry pick all commits in master, that match the tracking ID and create a new branch.";
echo "";
echo "Usage: $0 traackingID";
echo "";
exit 1;
fi
#If $1 doesn't match a AGW-<number> pattern, thrown an error
user="$(id -u -n)" > /dev/null
echo "You are - $user"
branchname=$user"_"$1"_review"
echo "Creating branch - $branchname"
basecommit="$(git log master --pretty=oneline --reverse | grep "$1" | head -1 | cut -d ' ' -f 1)""~1"
echo "Checking out from $basecommit"
git checkout --orphan $branchname $basecommit > /dev/null
git commit -m "$1"
git rev-list master --reverse --grep="$1" | 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