1

I'm using the recommended GitPython module, but I cannot figure out how to construct the following command:

git diff --name-status ec04352 b945e6c 

I would like to get information about all modified files between two commits, and this command does exactly what I want to do. Could you comment on it?

declension
4,20524 silver badges27 bronze badges
asked Dec 10, 2014 at 12:07

2 Answers 2

6

This is one way to do it:

import git
repo = git.Repo('path/to/your/repo')
print repo.git.diff('ec04352', 'b945e6c', **{'name-status': True})

It is, however, going through the backdoor.

You should be able to do something like this:

a = repo.commit('ec04352')
b = repo.commit('b945e6c')
diffs = a.diff(b)
>>> a
<git.Commit "ec04352">
>>> b
<git.Commit "b945e6c">
>>> print diffs[0]
zip/JSONzip.java
=======================================================
lhs: 100644 | d8e3ac652a5a5158692fa5fc131340c03dffd08e
rhs: 100644 | 220686de3dcb0dd17a54cbc5f8e44df261b664d5
>>> 

You'll need to play with the Diff object to figure out the difference.

answered Dec 10, 2014 at 12:41
Sign up to request clarification or add additional context in comments.

Comments

2

See Obtaining Diff Information in the GitPython manual for a few example on how to get the diff information between two commits.

hcommit = repo.head.commit
idiff = hcommit.diff() # diff tree against index
tdiff = hcommit.diff('HEAD~1') # diff tree against previous tree
wdiff = hcommit.diff(None) # diff tree against working tree

These commands return a DiffIndex, which contain iter_change_type which you can call with each of the four different change types ('A', 'D', 'R', 'M') to get the paths that have been changed (added, deleted, renamed, modified).

answered Dec 10, 2014 at 12:40

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.