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 OverflowFor 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.
You can try PyDriller instead (it uses GitPython internally). I'm the owner.
I created it so it's easier to use then other frameworks:
for commit in RepositoryMining("path_to_repo", filepath="here_the_file").traverse_commits():
# here you have the commit object
print(commit.hash)
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]))
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
» pip install python-git-info
GitPython uses the module logging. By adding logging.basicConfig(level=logging.DEBUG) before your code, it prints logs like
DEBUG:git.cmd:Popen(['git', 'fetch'], cwd=E:\path\foo, universal_newlines=False, shell=None)
If you want it to print formatted logs as you expect, you could modify GitPython's source code. I'm using Python 2.7 and my GitPython is installed at C:\Python27\lib\site-packages\git. You can run git.__file__ in REPL to find your installation directory. In the file C:\Python27\lib\site-packages\git\cmd.py, you can find a method def execute. It calls subprocess.Popen to run the command. You can modify the line log.debug before Popen or just insert print(' '.join(cmd)) at a proper line. If you are using Python 3.3 or newer, you could also refer to this answer on how to print the command with subprocess.
You could also:
pull = self.repo.git.pull('--rebase')
log.info(pull)