Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git python can't show log between 2 commits?

using GitPython and trying to print logs:

print(self._git.log('{}..{} --pretty=tformat:%h:%s:%cn'.format(self.good, self.bad).split()))

where:

self._repo = git.Repo(path=repo, search_parent_directories=True)
self._git = git.Git(self._repo.working_tree_dir)

and getting this error

git.exc.GitCommandError: Cmd('git') failed due to: exit code(128)
  cmdline: git log 7900edaa7973536bd53bea35404772b46735c46a..83bd42668003bb6075e44fd44ec21a39dd90096f --pretty=tformat:%h:%s:%cn
  stderr: 'fatal: Invalid revision range 7900edaa7973536bd53bea35404772b46735c46a..83bd42668003bb6075e44fd44ec21a39dd90096f'

but when running the command from the error (i.e. git log 7900edaa7973536bd53bea35404772b46735c46a..83bd42668003bb6075e44fd44ec21a39dd90096f --pretty=tformat:%h:%s:%cn) from bash, I get a normal result.

It did work, when I replaced the commits with count (print(self._git.log('-4 --pretty=tformat:%h:%s:%cn'.split())))

like image 984
CIsForCookies Avatar asked Aug 11 '26 23:08

CIsForCookies


1 Answers

This is working for me in a test project with python 2.7.16 and GitPython 2.1.14.

Base on the error message (invalid revision range) I think your python code is using a different repository than where you are running the git command from the shell.

like image 172
Doug Richardson Avatar answered Aug 13 '26 17:08

Doug Richardson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!