Diff commit messages of two branches with gitpython
<p>At work, we have a workflow where each branch is "named" by date. During the week, at least once, the latest branch gets pushed to production. What we require now is the summary/commit messages of the changes between the latest branch in production vs the new branch via gitpython.</p>

<p>What I have tried to do:</p>

<pre><code>import git

g = git.Git("pathToRepo")
r = git.Repo("pathToRepo")
g.pull() # get latest

b1commits = r.git.log("branch1")
b2commits = r.git.log("branch2")
</code></pre>

<p>This give me all of the commit history from both branches but I can't figure out how to compare them to just get the newest commit messages.</p>

<p>Is this possible to do in gitPython? Or is there a better solution?</p>

<p>I figured it out:</p>

<pre><code>import git

g = git.Git(repoPath+repoName)
g.pull()
commitMessages = g.log('%s..%s' % (oldBranch, newBranch), '--pretty=format:%ad %an - %s', '--abbrev-commit')
</code></pre>

<p>Reading through the Git documentation I found that I can compare two branches with this syntax <code>B1..B2</code>. I tried the same with gitpython and it worked, the other parameters are there for a custom format.</p>

python git-commit git-log gitpython