28 Jan 2015

git cherry

Today I learned about git cherry. I knew about cherry-pick, which I use from time to time, but this is a different cherry.

In one of my projects, a desktop application, I maintain a branch per released version. This way I have branches like production-5.0, production-5.1 and so on.

From time to time I make some changes that need to go to master too. Instead of merging and getting a lot of noise, I sometimes cherry-pick those commits to add them to master.

The problem is that sometimes I don’t know which commits has been back-ported to master. git cherry is useful in this situation:

    $ git cherry -v master production-5.1
    - d326c2997eb355eb79d4974e2e4a75a4bcc7755d gen_searches fix description
    - d326c2997eb355eb79d4974e2e4a75a4bcc7755d gen_searches sex filter
    + 7b804f83de325f31b43f372793a5acaf563b8ec9 select result and compare it as known parental against other results

In this example, the first two commits are already on master, and the third one is not.

Now I only have to cherry-pick the third one and I’m done.