Skip to content
Advertisement

Get time of last commit for Git repository files via Python?

I have a Git repository with several thousand files, and would like to get the date and time of the last commit for each individual file. Can this be done using Python (e.g., by using something like os.path.getmtime(path))?

Advertisement

Answer

An interesting question. Below is a quick and dirty implementation. I’ve used multiprocessing.Pool.imap() to start subprocesses because it’s convenient.

JavaScript

Example output:

JavaScript

Edit: Updated to use the os.devnull (that works on ms-windows as well) instead of /dev/null.

Edit2: Used startupinfo to suppress command prompts popping up on ms-windows.

Edit3: Used __future__ to make this compatible with both Python 2 and 3. Tested with 2.7.9 and 3.4.3. Now also available on github.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement