Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git log --follow, the gitpython way

I am trying to access the commit history of a single file as in:

git log --follow -- <filename> 

I have to use gitpython, so what I am doing now is:

import git  g = git.Git('repo_dir')  hexshas = g.log('--pretty=%H','--follow','--',filename).split('\n')  

then I build commit objects:

repo = git.Repo('repo_dir') commits = [repo.rev_parse(c) for c in r] 

Is there a way to do it in a more gitpython-ic way? I tried both commit.iter_parents() and commit.iter_items(), but they both rely on git-rev-list, so they don't have a --follow option.

like image 604
Alberto Bacchelli Avatar asked Apr 09 '12 12:04

Alberto Bacchelli


People also ask

Is git log in chronological order?

The most basic and powerful tool to do this is the git log command. By default, with no arguments, git log lists the commits made in that repository in reverse chronological order; that is, the most recent commits show up first.

What is git command to see a repository's history?

`git log` command is used to view the commit history and display the necessary information of the git repository. This command displays the latest git commits information in chronological order, and the last commit will be displayed first.

How do I commit a git log?

On GitHub.com, you can access your project history by selecting the commit button from the code tab on your project. Locally, you can use git log . The git log command enables you to display a list of all of the commits on your current branch. By default, the git log command presents a lot of information all at once.


2 Answers

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.

like image 64
mimin0 Avatar answered Sep 16 '22 14:09

mimin0


I'd suggest you to use PyDriller instead (it uses GitPython internally). Much easier to use:

for commit in RepositoryMining("path_to_repo", filepath="here_the_file").traverse_commits():     # here you have the commit object     print(commit.hash) 
like image 30
Davide Spadini Avatar answered Sep 20 '22 14:09

Davide Spadini