In my project there are a stable
branch and a dev
branch. Commits are cherry-picked from dev
branch to stable
branch.
In order to filter all commits on dev
that have not been merged to stable
, git cherry -v stable dev
looks like a good choice. However it identifies equivalence by diff, which usually changes after resolving merge conflict during cherry-pick
:
The equivalence test is based on the diff, after removing whitespace and line numbers. git-cherry therefore detects when commits have been "copied" by means of git-cherry-pick(1), git-am(1) or git-rebase(1).
I was wondering that is there any command that works like git cherry
, but identifies equivalent commits by commit message?
It seems that there is no direct way to do this, so I wrote a short script:
Explanation:
git cherry -v stable dev | grep + | cut -d ' ' -f 3- > /tmp/unmerged
writes commit messages of commits that only exist ondev
branch. These commits include those have been cherry-picked and changed tostable
branch, and we need to filter out these commits in the next step.xargs -a /tmp/unmerged -I{} git --no-pager log stable --pretty=oneline --grep {} | cut -d ' ' -f 2- > /tmp/cherry-picked
outputs messages of commits from (1) that appears with the same message onstable
. In other words,/tmp/cherry-picked
stores all commits that are cherry-picked and changed fromdev
tostable
.Finally,
diff /tmp/unmerged /tmp/cherry-picked
gives out all commits ondev
where no commit with identical commit message is found onstable
.