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

前端 未结 5 1167
故里飘歌
故里飘歌 2021-01-14 05:12

I am trying o grasp gitpython module,

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

but tdiff = hcommit.diff(\'HEAD^ H

5条回答
  •  我在风中等你
    2021-01-14 05:17

    Sorry to dig up an old thread... If you need to find out which files changed, you can use the .a_path or .b_path attribute of a diff object depending on which one you feed it first. In the example below I'm using the head commit as a so I look at a.

    e.g:

    # this will compare the most recent commit to the one prior to find out what changed.
    
    from git import repo
    
    repo = git.Repo("path/to/.git directory")
    repoDiffs = repo.head.commit.diff('HEAD~1')
    
    for item in repoDiffs:
        print(item.a_path)
    

提交回复
热议问题