2

I'm begin in python and trying to use GitPython and I desperately tries to make working this module.

I've seen on many website that documentation is poor and the example I follow doesn't seems to work.

I've try this on Windows (2012/ Python 3.5):

# -*-coding:Latin-1 -*

from git import *

path = ('C:\\Users\\me\\Documents\\Repos\\integration')
repo = Repo(path)
assert repo.bare == False

repo.commits()

os.system("pause")

And this on Linux (Debian/Python 2.7) :

from git import Repo

repo = Repo('/home/git/repos/target_repos')
assert repo.bare == False

repo.commits ()

But anyway, I've no result... And finish with this error :

Traceback (most recent call last):
  File "gitrepo.py", line 6, in <module>
    repo.commits ()
AttributeError: 'Repo' object has no attribute 'commits'

in the two case.

My question is the following :

  1. Is there a way to make this module work ? All the link I found are old...
  2. If yes, please help me or giving me an example.
  3. If not, is there another module ? I've trying to install Dulwich but no succes (on Windows only)
  4. I've seen there is a way by using fab ? Is it possible to manipulate git with that ?

The goal is to manage git with python in the future, as well as other things for integration.

Thank you for your answer.

4
  • What does repo.head get you? Commented Feb 16, 2015 at 10:25
  • when I put that repo.head() in my file.py, I get that TypeError: 'HEAD' object is not callable if that's your question ? Commented Feb 16, 2015 at 10:31
  • @minitech Does i have something else to configure before ? Commented Feb 16, 2015 at 10:38
  • It’s just repo.head. Not a function. Commented Feb 16, 2015 at 18:26

1 Answer 1

4

The module works fine, you're not using it properly. If you want to access the commits in a git repository, use Repo.iter_commits(). The method commits() you're trying to use doesn't exist in GitPython.Repo. You can check the official module documentation here for all supported operations and attributes.

See below for a working example

from git import Repo, Commit

path = "test_repository"

repo = Repo(path)

for commit in repo.iter_commits():
    print "Author: ", commit.author
    print "Summary: ", commit.summary

This shows the author and summary for every commit in the repository. Check the Commit object's documentation for operations and accessing additional information they carry (e.g. the commit hash, date, etc.)

Sign up to request clarification or add additional context in comments.

4 Comments

Ok. In fact, when i type the command with python -v, I've some results : with repo.untracked_files it show the untracked files. But with repo.iter_commits() it ouput something strange : <generator object Commit._iter_from_process_or_stream at 0x0000000F94E4EDB0>... I will work on the documentation.
Many thanks. It gives me a good starting example and working perfectly.
@mestra I recommend you to start learning python basics as well, e.g. work through tutorials. That might help prevent misunderstandings in future, and will help getting results faster with anything you try to accomplish in python.
@Byron I have already some base in Python, but when i've tryed to use Git-Python I was a little lost... the documentation is a bit hard to understand... maybe for a french like me ^^.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.