1

I don't understand the difference between the output of git log -p and that of gitpython in terms of diffs.

For example, for some merge commit f534e1..., git log -p gives:

commit f534e1...
Merge: ....
Author: ....
Date: ...
Merge pull request ... from ...

with no diff, which I assume to be correct (the diff comes with the next log entry - one of the parents of f534e1...).

I would like to achieve the same effect with gitpython. I'm trying:

repo = Repo("...")
for c in repo.iter_commits():
 print c.hexsha
 print c.summary
 print c.diff()

I get:

f534e1...
Merge pull request ... from ...
[<git.diff.Diff object at 0x102cd3490>]

with some diff.

What diff is this? Why do I get it here? How can I mimic the behavior of git log -p?

asked Apr 8, 2015 at 23:43
3
  • What are the actual properties of the git.diff.Diff object? Commented Apr 8, 2015 at 23:49
  • gitpython.readthedocs.org/en/latest/… Commented Apr 8, 2015 at 23:51
  • Huh, I'd read the docs :) I asked what are the values of those properties? Have you compared the resulted diff (if it actually contains any significant difference, not just an object of git.diff.Diff class), with git diff ... with each of the merge parents. Commented Apr 9, 2015 at 5:00

1 Answer 1

2

According to the documentation, c.diff() will compare the commit against the index, i.e. staged changes.

It appears that git log -p will produce a special-format diff against all of the given commit's parents. Something roughly comparable can be achieved with the following code (based on your example).

repo = Repo("...")
for c in repo.iter_commits():
 print c.hexsha
 print c.summary
 for p in c.parents:
 handle_diff(c.diff(p))

The latter would yield a Diff object with all relevant information.

If what you really want is the exact format produced by git log -p, you may also call repo.git.log(p=True) and parse the output yourself.

answered Apr 9, 2015 at 6:27
Sign up to request clarification or add additional context in comments.

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.