A RetroSearch Logo

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

Search Query:

Showing content from http://stackoverflow.com/questions/55004770/how-to-use-git-log-oneline-in-gitpython below:

How to use git log --oneline in gitpython

I'm trying to extract list of commit messages by giving a start sha & end sha. It's easy in git using git log. But am trying to do it through gitpython library. Could someone help me to achieve this?

in Git the command is like this :

git log --oneline d3513dbb9f5..598d268f

how do i do it with gitpython?

aysabzevar

1,18033 gold badges2323 silver badges3434 bronze badges

asked Mar 5, 2019 at 14:10

sbkhbksbkhbk

3922 silver badges1010 bronze badges

The GitPython Repo.iter_commits() function (docs) has support for ref-parse-style commit ranges. So you can do:

import git
repo = git.Repo("/path/to/your/repo")
commits = repo.iter_commits("d3513dbb9f5..598d268f")

Everything after that depends on the exact formatting you want to get. If you want something similar to git log --oneline, that would do the trick (it is a simplified form, the tag/branch names are not shown):

for commit in commits:
    print("%s %s" % (commit.hexsha, commit.message.splitlines()[0]))

answered Sep 4, 2019 at 13:31

imphilimphil

3144 bronze badges

0

You can use pure gitpython:

import git
repo = git.Repo("/home/user/.emacs.d") # my .emacs repo just for example
logs = repo.git.log("--oneline", "f5035ce..f63d26b")

will give you:

>>> logs
'f63d26b Fix urxvt name to match debian repo\n571f449 Add more key for helm-org-rifle\nbea2697 Drop bm package'

if you want nice output, use pretty print:

from pprint import pprint as pp
>>> pp(logs)
('f63d26b Fix urxvt name to match debian repo\n'
 '571f449 Add more key for helm-org-rifle\n'
 'bea2697 Drop bm package')

Take a note that logs is str if you want to make it a list, just use logs.splitlines()

Gitpython had pretty much all similar API with git. E.g repo.git.log for git log and repo.git.show for git show. Learn more in Gitpython API Reference

answered Apr 6, 2019 at 3:07

azzamsaazzamsa

2,16522 gold badges2323 silver badges2929 bronze badges

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.


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