A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://stackoverflow.com/questions/77997040/git-diff-against-master-branch-using-gitpython below:

python - Git diff against master branch using GitPython

I must be dense, but I haven't been able to find a solution yet.

I am trying to get a list of all of the members (in all commits or not committed yet) that have changed on a branch in my Python program. On the command line, I use "git diff --name-only master" which does exactly what I want.

By using:

commit = repo.head.commit
master = repo.heads.master
for member in commit.diff(master).iter_change_type("M"):
    members.append(member.a_path)

I get a list of modified members from the latest commit. It does not include anything from prior commits or anything that hasn't been committed yet (I also do the same command with type "A" for anything added, I'm not worried about renames or deletes yet).

This works:

member_list = repo.git.diff("--name-only", "master").splitlines()

Which returns what I want, but it seems there should be a more "pythonic" way of doing this.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4