For example, I have a dev
branch and a stable
branch.
In case I have cherry-picked several commit from dev
to stable
.
Is there any way to let Git aware of the cherry-picked commits, and avoid doubly-merging it if I later merge, rebase or cherry-pick an overlapped range, from dev
back to stable
? (for which is a basic merge tracking feature in SVN)
There is actually a command named git cherry that prints every commit that is not merged between two branches.
For each printed commit, the "+" sign means you can merge it, the "-" sign means you already cherry-pick that commit.
The output is far from being pretty.
For those who came from SVN and are used to svnmerge.py, I made a "svnmerge avail -l" equivalent bash script for git, that I called gitavail:
#!/bin/bash
# get current branch
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
# get tracked branch (1st argument), if no arg or arguments are only options, assume master
if test -z $1 || grep -q '^-' <<< $1;
then TRACKED_BRANCH=master
else TRACKED_BRANCH=$1; shift
fi
# Log commits available for merge from tracked branch
LOG_OPTIONS=$*
for i in $(git cherry $CURRENT_BRANCH $TRACKED_BRANCH | egrep '^\+' | awk '{print $2}'); do git --no-pager log -n1 $i ${LOG_OPTIONS}; echo; done
Assuming you are on a branch, and you want to list what is eligible to merge from master branch, just run:
gitavail --name-status
And you'll have an output very similar to "svnmerge avail -l".
I guess the cherry-pick commits must not be manually modified (what about conflicts?), if the patch id changes, git cherry won't realize the commit has already been cherry-picked.