Skip to content

Instantly share code, notes, and snippets.

@flashingpumpkin
Created July 5, 2012 12:42
Show Gist options
  • Select an option

  • Save flashingpumpkin/3053479 to your computer and use it in GitHub Desktop.

Select an option

Save flashingpumpkin/3053479 to your computer and use it in GitHub Desktop.
Quick n dirty hack to compare two branches - eg show missing commits.
#!/usr/bin/env python
import sys
import os
def run():
b1 = sys.argv[1]
b2 = sys.argv[2]
checkout = lambda branch: os.popen('git checkout %s' % branch)
log = lambda: os.popen('git log --pretty=oneline').read()
formatter = lambda data: map(lambda line: line.split(' ')[0], data.split('\n'))
checkout(b1); b1c = formatter(log())
checkout(b2); b2c = formatter(log())
print 'Commits on %s but not on %s: ' % (b2, b1)
difference = map(lambda commit: os.popen('git log %s --pretty=oneline --no-walk' % commit).read(),
list(set(b2c) - set(b1c)))
print ''.join(map(lambda line: 'commit %s' % line, difference))
if __name__ == "__main__":
if not len(sys.argv) == 3:
print "Usage: git-compare from-branch to-branch"
sys.exit(1)
else:
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment