Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying o grasp gitpython module,

hcommit = repo.head.commit
tdiff = hcommit.diff('HEAD~1')

but tdiff = hcommit.diff('HEAD^ HEAD') doesn't work !! neither does ('HEAD~ HEAD').,

I am trying to get the diff output !

share|improve this question
1  
I admit to never having used the gitpython code, but it seems obvious that if hcommit is repo.head.commit, it's bound to that particular commit, and thus hcommit.diff means "diff that particular commit, against something else". To get diffs of two arbitrary commits, you'd have to choose some other starting-point. –  torek Feb 25 at 17:39

1 Answer 1

up vote 0 down vote accepted

I figured out how to get the git diff using gitPython.

import git
repo = git.Repo("path/of/repo/")

# the below gives us all commits
repo.commits()

# take the first and last commit

a_commit = repo.commits()[0]
b_commit = repo.commits()[1]

# now get the diff
repo.diff(a_commit,b_commit)

Voila !!!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.