Ciasto piekarz Ciasto piekarz - 1 year ago 92
Git Question

how to do a git diff of current commit with last commit using gitpython?

I am trying o grasp gitpython module,

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

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

I am trying to get the diff output !

Answer Source

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

# take the first and last commit

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

# now get the diff

Voila !!!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download