Getting a file’s creation and modification time

To get the time a file was first added to a git repository and when it was last modified, use the following command: 1

git log --follow --format=%ad --date iso-strict FILE | sed -n '1p; $p'

If you need to be more selective about which commits should count based on what changed, you can view every commit a file was added or modified in along with a diff showing that happened with the following command: 1

git log -p --stat --follow --date iso-strict FILE

Footnotes

  1. 20241009063425 2