Git Tip of the Day – find commits (not) merged upstream

Yes, the series is not over, I’m back! 🙂 I don’t give up so easily.

When working with git, you might have come across the situation: You found a bug in a project and decided to write a patch for it. You cloned their git repo, wrote a patch and posted it into their mailing conference. They approved the patch and said that a responsible person would commit it to the master branch soon.

Some weeks later you decided to check whether your patch had been already committed. How do you do that?

You can grep the log for your name, but what if they didn’t assign it as the author name properly? You can grep the log for your commit summary, but what if they changed it?

The answer is: You can use “git cherry”. This command will compare commits in your branch against its tracking branch, and differentiate commits that you have in common from commits that are in your local branch only. However, it does not compare SHA1 commit checksums, it compares patch IDs, which do not change if some commit metadata are changed. Therefore if your very diff stayed intact (although commit metadata changed), “git cherry” would consider them as the same commit.

This is an example that prints changes between my HEAD and its tracking branch:

$ git cherry -v
+ a7b769f180c59c4c14aefdde5c4736c0991af617 README update
+ 63e549e21eae448381bdfed043320cb31add7481 TODO update

Commits appearing only in my local branch are prefixed with “+”, commits appearing in both branches are prefixed with “-“. You can see that I have two commits in my HEAD (pun intended) that were not yet merged upstream and also there are no commits in upstream that would we have in common since I branched it.

I can also specify branch targets. Let’s say I want to compare master and stable branches in my project:

$ git cherry -v stable master
+ 495a213b6e79b48bdfb39e7befa01d18955fefbf cron: decrease scheduling period for koji watcher to 30 min
+ 97e6316647b90e39813ac24df84a76e0f8aaaf57 Changed the overall architecture from hooks to event/watcher + refactored autoqa
- 42fe19e89bbaf275be0c03e64a4c2007838b77c7 initscripts: fix unassigned variable causing crash
+ f875df5f3975aba0945871f2dffb786b3efbfbf7 compose_tree: Add -p PUNGI_ARGS value
+ 6b7aa3701b1d45886f9907fb77aa79dd70099918 remove front-ends (israwhidebroken) directory
+ f76e9d2d1c79e58767cae896aeeef0aadc250639 286 - upgradepath reporting; minor depcheck changes
- e988b38567c5d07a140081ad8a0dd6b0ceb5b462 fix for #292 - When publishing results to bodhi, link to output.log
+ 53aa452e605b61944d6b657bc09813972be2b262 depcheck: download only necessary archs
- a8ee9f32f5df5fcd4c830d28f8253287336b32e7 Update for autoqa-0.4.7
+ 5e26d21fbd9635e517cd90cc95dc8ca0e99ac282 compose_tree: add lorax to the list of packages to run for
+ 36dbec7ed1fb88e99df9a42551eb0c3dcc38a269 koji_utils: allow package download caching

You can see that there are many commits exclusively in master (prefixed with “+”), but some of the commits were cherry-picked to stable and therefore are the same in both branches (prefixed with “-“).

I’m sure you can find other usages.

Happy gitting!


Flattr this

Leave a Reply (Markdown syntax supported)

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s