If you have a git branch which you are working on which is a clone from an upstream ‘official’ branch, and you sometimes submit your commits to be integrated upstream, there’ll surely be times when your patches are not accepted or fall between the cracks. After a while it can get a little hairy to figure out which commits are unique to your branch and which ones are incorporated in the main repo.
The ‘git cherry’ command can help with this. It lists all commits in one branch which are not in another. It works like this simply:
git cherry -v upstream my_branch
The man page describes the command succinctly:
Every commit that doesn’t exist in the <upstream> branch has its id (sha1) reported, prefixed by a symbol. The ones that have equivalent change already in the <upstream> branch are prefixed with a minus (-) sign, and those that only exist in the <head> branch are prefixed with a plus (+) symbol.
import sys cherry = open(sys.argv, "r") filtr = open(sys.argv, "r") lines = filtr.readlines() unmatched =  for line in cherry.readlines(): plus, sha, message = line.split(" ", 2) for existing in lines: esha,emessage = existing.split(" ", 1) if message == emessage: break else: unmatched.append((sha, message)) for sha, message in unmatched: print "+ %s %s" % (sha, message)
$ git checkout upstream
$ git log --oneline >all_commits.txt
$ git cherry -v upstream my_branch >cherry_commits.txt
$ python filter_cherry.py cherry_commits.txt all_commits.txt