1

I have:

  • 5 modified but unstaged files
  • 2 modified and staged files
  • thus 7 modified files.

I know the following GitPython equivalents to git commands:

  • repo.index.diff(None) gives the same result as git diff - 5 modified but unstaged files
  • repo.index.diff('HEAD') surprisingly gives the same result as git diff --staged - 2 modified and staged files

Thus my question is, what is GitPython equivalent to git diff HEAD?

P.S. I can merge results of repo.index.diff(None) and repo.index.diff('HEAD') to get the desired output but it looks quite stupid...

1
  • The Git equivalent is of course to run git diff HEAD. There's no general-Python answer either, really, as you're looking for something built into the GitPython library. So the only appropriate tag here is gitpython... Commented Jan 31, 2020 at 15:29

2 Answers 2

1

The following worked for me:

repo = git.Repo('path/to/my/repo')
print(repo.git.diff(repo.commit()))

This showed the diff for both staged and unstaged modifications.

Sign up to request clarification or add additional context in comments.

Comments

0

The following worked for me using GitPython.

repo = git.Repo(".")
output = repo.index.diff("HEAD")

Comments

Your Answer

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.