Background: I have two branches, master and stable, with many commits on master that aren't on stable. I want to cherry-pick a number of those commits to stable, and then be able to use git log --merges-only stable..master
to see what's left.
However, if I just cherry-pick, git treats them as two commits and thus the 'git log' command doesn't help. E.g. given this:
# create a repo
mkdir cherry
cd cherry
git init
# add a commit on master
touch foo.txt
git add foo.txt
git commit -a -m 'commit 1'
# create a stable branch
git checkout -b stable
# add two more commits to master
git checkout master
touch bar.txt
git add bar.txt
git commit -m 'commit 2'
touch baz.txt
git add baz.txt
git commit -m 'commit 3'
# cherry-pick just one of those commits to stable
git checkout stable
git cherry-pick master
Then, I'd like to be able to see what commits are candidates for future cherry-picking on master, ideally using git log
, but it doesn't really answer my question:
> git log stable..master --pretty=oneline --no-merges
01550adab8993ceb1eec7bbc7a0e3de3550d63fc commit 3
8a3ea27aa50c887b603296bb9d4a36ccbfa35311 commit 2
However, TIL about git cherry
:
> git cherry stable master
+ 8a3ea27aa50c887b603296bb9d4a36ccbfa35311
- 01550adab8993ceb1eec7bbc7a0e3de3550d63fc
Where the entries prefixed with '+' are the candidates for future-cherry picking.
The
git cherry
command is designed for this purpose.