0

The following code prints the files which have been modified in current tree vs previous tree (if changed):

for modified in commit.diff('HEAD~1').iter_change_type('M'):                         
    print(modified.a_blob.path)      # prints all files modified

How to get number of lines added and deleted too? (Just like we do using git log --numstat).

Akhil Singhal
  • 151
  • 1
  • 7
  • Welcome to Stack Overflow! Please read [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and also [what have you tried](http://mattgemmell.com/what-have-you-tried/). – Jason Aller Feb 04 '18 at 01:44
  • @AkhilSinghal thank you for accepting my answer. My suggestion was that you open a _new_ question regarding the formatting issue rather than changing your existing question to a different one. – Matt Morgan Feb 04 '18 at 15:05
  • @MattMorgan Ok, I will. Thanks btw for guiding me. – Akhil Singhal Feb 04 '18 at 15:26
  • No problem man. Happy to help when I can! – Matt Morgan Feb 04 '18 at 15:30

1 Answers1

0

You can use git directly to do this from within gitpython:

the_git = repo.git
log = the_git.log('--numstat')

More here if you like: http://gitpython.readthedocs.io/en/stable/tutorial.html#using-git-directly

Matt Morgan
  • 4,900
  • 4
  • 21
  • 30
  • You should be executing this code in a context where `repo` is defined. I (mistakenly) assumed you understood that, since you would have needed that to have your above code working. If you want to post a more complete example I can try to help more. – Matt Morgan Feb 04 '18 at 14:33
  • **Update**-This did the work I was looking for. But the format of output is a single string of the form: **num(added)** **num(deleted)** **file-name** for all files which requires huge string manipulation to extract out the useful data. Can this output format of diff be somehow manipulated/changed, like list of lists or something else? – Akhil Singhal Feb 04 '18 at 14:34
  • I'm glad it worked. I'm sure the output could be changed, but that seems like a different question. You asked how to reproduce `git log --numstat`, which is what my answer does. Please ask about formatting as a separate question, and I or someone else would be happy to help! Since this answer does satisfy your original post, please accept it if you would. – Matt Morgan Feb 04 '18 at 14:38