6

gitpythonモジュールを把握しようとしているのですが、

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

しかし、tdiff = hcommit.diff('HEAD^ HEAD')うまくいきません!! どちらもしません('HEAD~ HEAD')

差分出力を取得しようとしています!

4

5 に答える 5

8
import git

repo = git.Repo('repo_path')
commits_list = list(repo.iter_commits())

# --- To compare the current HEAD against the bare init commit
a_commit = commits_list[0]
b_commit = commits_list[-1]

a_commit.diff(b_commit)

これにより、コミットの差分オブジェクトが返されます。これを達成する他の方法もあります。例(これはhttp://gitpython.readthedocs.io/en/stable/tutorial.html#obtaining-diff-informationからコピー/貼り付けされています):

```

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

    index = repo.index
    index.diff()                    # diff index against itself yielding empty diff
    index.diff(None)                # diff index against working copy
    index.diff('HEAD')              # diff index against current HEAD tree

```

于 2015-09-22T16:37:27.373 に答える
2

差分の内容を取得するには:

import git
repo = git.Repo("path/of/repo/")

# define a new git object of the desired repo
gitt = repo.git
diff_st = gitt.diff("commitID_A", "commitID_B")
于 2016-03-31T18:19:19.440 に答える
2

gitPython を使用して git diff を取得する方法を見つけました。

import git
repo = git.Repo("path/of/repo/")

# the below gives us all commits
repo.commits()

# take the first and last commit

a_commit = repo.commits()[0]
b_commit = repo.commits()[1]

# now get the diff
repo.diff(a_commit,b_commit)

出来上がり!!!

于 2014-02-26T07:33:34.430 に答える