1

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.

What I have tried to do:

import git
g = git.Git("pathToRepo")
r = git.Repo("pathToRepo")
g.pull() # get latest
b1commits = r.git.log("branch1")
b2commits = r.git.log("branch2")

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.

Is this possible to do in gitPython? Or is there a better solution?

asked Oct 4, 2016 at 13:50

2 Answers 2

3

I figured it out:

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

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

answered Oct 4, 2016 at 15:30
Sign up to request clarification or add additional context in comments.

Comments

2

This solution uses GitPython

import git
def get_commit_from_range(start_commit, end_commit):
 repo = git.Repo('path')
 commit_range = f"{start_commit}...{end_commit}"
 result = repo.iter_commits(commit_range)
 for commit in result:
 print(commit.message)
Martin Thoma
139k174 gold badges689 silver badges1.1k bronze badges
answered Nov 6, 2019 at 3:48

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.