For example,

With range time:

g = git.Git("C:/path/to/your/repo") 
loginfo = g.log('--since=2013-09-01','--author=KIM BASINGER','--pretty=tformat:','--numstat')
print loginfo

Output:

3       2       path/in/your/solutions/some_file.cs

You can see the added lines, removed lines and the file with these changes.

Answer from mimin0 on Stack Overflow
🌐
GitHub
github.com › gitpython-developers › GitPython › issues › 157
How to use git command 'git log -p' with GitPython · Issue #157 · gitpython-developers/GitPython
May 2, 2014 - I need use GitPython to do one command, the look like git command " git log -p". I read the tutorial but I still don't know how to do it . I use the command master.log() ,but couldn&#...
Author   fengqiaoye
🌐
Readthedocs
gitpython.readthedocs.io › en › 0.1.7 › reference.html
API Reference — GitPython 0.1.7 documentation
Represents a git repository and allows you to query references, gather commit information, generate diffs, create and clone repositories query the log.
🌐
Readthedocs
gitpython.readthedocs.io › en › stable › tutorial.html
GitPython Tutorial — GitPython 3.1.46 documentation
Additionally, GitPython adds functionality to track a specific branch, instead of just a commit. Supported by customized update methods, you are able to automatically update submodules to the latest revision available in the remote repository, as well as to keep track of changes and movements of these submodules. To use it, set the name of the branch you want to track to the submodule.$name.branch option of the .gitmodules file, and use GitPython update methods on the resulting repository with the to_latest_revision parameter turned on.
Top answer
1 of 1
8

You can get all the repository commits using:

import git
repo = git.Repo("/home/user/.emacs.d")
commits = list(repo.iter_commits("master", max_count=5))

Then you can identify yourself what kind of data gitpython offers:

dir(commits[0])

Some of them are:

  • author
  • committed_datetime
  • hexsha
  • message
  • stats

Take an example:

>>> commits[0].author
<git.Actor "azzamsa <[email protected]>">

>>> commits[0].hexsha
'fe4326e94eca2e651bf0081bee02172fedaf0b90'

>>> commits[0].message
'Add ocaml mode\n'

>>> commits[0].committed_datetime
datetime.datetime(1970, 1, 1, 0, 0, 0, tzinfo=<git.objects.util.tzoffset object at 0x7fb4fcd01790>)

(committed_datetime outputs datetime object with locale object)

If you want to check if a commit contains a file (which is usable if you want to grab all commit from that file). You can use:

def is_exists(filename, sha):
    """Check if a file in current commit exist."""
    files = repo.git.show("--pretty=", "--name-only", sha)
    if filename in files:
        return True

Then to get all commit from a file:

def get_file_commits(filename):
    file_commits = []
    for commit in commits:
        if is_exists(filename, commit.hexsha):
            file_commits.append(commit)

    return file_commits

e.g I want to take all commits from 'init.el' file:

initel_file_commits = get_file_commits('init.el')

>>> initel_file_commits
[<git.Commit "fe4326e94eca2e651bf0081bee02172fedaf0b90">, <git.Commit
"e4f39891fb484a95ea76e8e07244b908e732e7b3">]

See that the function working correctly:

>>> initel_file_commits[0].stats.files
{'init.el': {'insertions': 1, 'deletions': 0, 'lines': 1}, 'modules/aza-ocaml.el': {'insertions': 28, 'deletions': 0, 'lines': 28}}

>>> initel_file_commits[1].stats.files
{'init.el': {'insertions': 1, 'deletions': 0, 'lines': 1}, 'modules/aza-calfw.el': {'insertions': 65, 'deletions': 0, 'lines': 65}, 'modules/aza-home.el': {'insertions': 0, 'deletions': 57, 'lines': 57}}

Hope it helps.

🌐
Azzamsa
azzamsa.com › n › gitpython-intro
Getting Started with GitPython - azzamsa.com
December 14, 2019 - The first step is you need to know what the command and parameters look like in git, then the second step is passing those parameters to the GitPython git command. Some of the examples: ... $ git log --oneline b645f6e..86f3c62 86f3c62 (HEAD -> master) third commit 6240bd6 (third, second-branch) ...
🌐
GitHub
gist.github.com › simonw › 091b765a071d1558464371042db3b959
Python function for retrieving all git commits (from "git log" in the current directory) as a useful data structure · GitHub
Python function for retrieving all git commits (from "git log" in the current directory) as a useful data structure - example_output.json
🌐
Read the Docs
app.readthedocs.org › projects › gitpython › downloads › pdf › stable pdf
GitPython Documentation Release 3.1.46 Michael Trier Jan 01, 2026
January 1, 2026 - There is more functionality in there, like the ability to archive repositories, get stats and logs, blame, and probably a ... Check the unit tests for an in-depth introduction on how each function is supposed to be used. ... Chapter 3. GitPython Tutorial ... Current GitPython version. git.refresh(path: str | os.PathLike[str] | None = None) →None
Find elsewhere
🌐
GitHub
github.com › gitpython-developers › GitPython › blob › master › git › refs › log.py
GitPython/git/refs/log.py at master · gitpython-developers/GitPython
GitPython is a python library used to interact with Git repositories. - GitPython/git/refs/log.py at master · gitpython-developers/GitPython
Author   gitpython-developers
🌐
AskPython
askpython.com › home › step-by-step guide to checking out a commit id with gitpython
Step-by-Step Guide to Checking Out a Commit ID with GitPython - AskPython
April 10, 2025 - The ‘checkout’ command tells ... on the commit. Likewise, the ‘log()’ function tracks history or retrieves data like author details, date, and time from the commits....
🌐
GitHub
github.com › gitpython-developers › GitPython › issues › 817
use repo.git.log(p=True),No matter print to stdout or write to file it is happen Exception:MemoryError. · Issue #817 · gitpython-developers/GitPython
December 23, 2018 - For example: ==========gitpythonTest.py======== import git git.Repo.clone_from(url='https://github.com/ingbrzy/Xiaomi.eu-MIUIv10-XML-Compare.git', to_path='/tmp/Xiaomi') repo = git.Repo('/tmp/Xiaomi',odbt=git.GitDB) commitLogText = repo.git.log(p=True) print (commitLogText) ====python gitpythonTest.py result==== Traceback (most recent call last): File "test.py", line 5, in print (commitLogText) MemoryError ·
🌐
Readthedocs
gitpython.readthedocs.io › en › 2.0.1 › tutorial.html
GitPython Tutorial — GitPython 2.0.1 documentation
Additionally, GitPython adds functionality to track a specific branch, instead of just a commit. Supported by customized update methods, you are able to automatically update submodules to the latest revision available in the remote repository, as well as to keep track of changes and movements of these submodules. To use it, set the name of the branch you want to track to the submodule.$name.branch option of the .gitmodules file, and use GitPython update methods on the resulting repository with the to_latest_revision parameter turned on.
🌐
GitHub
github.com › gitpython-developers › GitPython › issues › 710
log does not work when used with --pretty=%P · Issue #710 · gitpython-developers/GitPython
December 19, 2017 - GitCommandError Traceback (most recent call last) <ipython-input-20-082da8bbf0c1> in <module>() 1 #%% ----> 2 print(REPO.git.log(' --pretty=%P -n 1 202bfa07e1fbaf7d210468a2ca6c7f4352fc2b25')) 3 # for each_line in REPO.git("log --pretty=%P -n 1 202bfa07e1fbaf7d210468a2ca6c7f4352fc2b25").split("\n"): 4 # print(each_line) 5 ~/anaconda3/envs/gitwork/lib/python3.6/site-packages/git/cmd.py in <lambda>(*args, **kwargs) 423 if name[0] == '_': 424 return LazyMixin.__getattr__(self, name) --> 425 return lambda *args, **kwargs: self._call_process(name, *args, **kwargs) 426 427 def set_persistent_git_opti
Author   Shreeasish
🌐
feststelltaste
feststelltaste.de › reading-a-git-repos-commit-history-with-pandas-efficiently
Reading a Git repo's commit history with Pandas efficiently
August 29, 2017 - This is way more faster than using GitPython’s object representation of the commits and makes it possible to have everything we need in one notebook. We use in-memory reading by using StringIO to avoid unnecessary file access. This avoids storing the Git output on disk and read it from from disc again. This method is faster, too. We also exploit Pandas’ read_csv method even more. This makes the transformation of the Git log ...
🌐
PyPI
pypi.org › project › python-git-info
python-git-info · PyPI
Download URL: python_git_info-0.8.3-py3-none-any.whl ... See more details on using hashes here. ... AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page
      » pip install python-git-info
    
Published   Apr 12, 2023
Version   0.8.3
🌐
Readthedocs
gitpython.readthedocs.io › en › stable › reference.html
API Reference — GitPython 3.1.46 documentation
keep_going – If True, we will ignore but log all errors, and keep going recursively. Unless dry_run is set as well, keep_going could cause subsequent/inherited errors you wouldn’t see otherwise. In conjunction with dry_run, it can be useful to anticipate all errors when updating submodules. ... Optional dictionary containing the desired environment variables. Note: Provided variables will be used to update the execution environment for git.
🌐
Waylon Walker
waylonwalker.com › git-python-all-commits
List all git commits with GitPython - Waylon Walker
May 9, 2022 - next(commits) # <git.Commit "d125317892d0fab10a36638a2d23356ba25c5621">
🌐
GitHub
github.com › gitpython-developers › GitPython › issues › 308
Feature Request: git log for specific directories · Issue #308 · gitpython-developers/GitPython
July 1, 2015 - >>> import git >>> git.Repo().git.log('--pretty=format:%h -- master') '808810fbfc4bd58891e43fa641e0bb6137c3fc97 -- master\na8be92733c87b09c1592fdb7200633f9fee0354d -- master\n09e7a7be446393052923b2baf72537cbd1d5bf6a -- master\n79c9c62d92d13755cdc398c33249176b77047e38 -- master\n...
Author   ben-en