Get Time of First Commit of a File

First published:

Last Edited:

Number of edits:

<p> In <a class="wikilink" href="/git/"> git </a> , to get the time of the first commit for every file in a directory, it is enough to run the following: </p> <pre class="codehilite"><code>$ git log --format=format"%ci" --name-only --diff-filter=A </code></pre> <p> Which will produce something like this: </p> <pre class="codehilite"><code>2020-10-03 15:06:25 +0200 content/Dispertech.md content/things I've done.md 2020-10-01 14:57:15 +0200 static/14092.jpg static/Aquiles.jpg static/aquiles_square.jpg static/deardisya.ttf 2020-10-01 12:21:03 +0200 content/digital garden tos.md content/optimization.md content/there is more to data than what meets the eye.md content/what is a machine learning algorithm.md content/why backlinks are the core of my digital garden.md </code></pre> <p> The date and time of the commit and the files that were added. </p> <p> The important parts are: <code> --diff-filter=A </code> will only look at when files are added comparing one commit with the previous one. We can also use <code> D </code> to see deleted files, <code> M </code> for modified, or <code> R </code> for renamed. <a href="https://git-scm.com/docs/diff-options"> The docs </a> explain all the rest of choices. </p> <p> <code> --name-only </code> will output the name of the files, while the <code> --format </code> decides how to output the information. Out of the box, we have these choices: </p> <ul> <li> oneline </li> <li> short </li> <li> medium </li> <li> full </li> <li> fuller </li> <li> reference </li> <li> email </li> <li> raw </li> </ul> <p> Or we can specify our own formatting, by making use of <a href="https://git-scm.com/docs/git-log#_pretty_formats"> pretty formats </a> . Some examples would be: </p> <pre class="codehilite"><code>%ci </code></pre> <p> Commit date </p> <pre class="codehilite"><code>%cn </code></pre> <p> Committer name </p> <pre class="codehilite"><code>%s </code></pre> <p> Commit subject (the message) </p>

Backlinks

These are the other notes that link to this one.

Nothing links here, how did you reach this page then?

Comment

Share your thoughts on this note. Comments are not public, they are messages sent directly to my inbox.
Aquiles Carattino
Aquiles Carattino
This note you are reading is part of my digital garden. Follow the links to learn more, and remember that these notes evolve over time. After all, this website is not a blog.
© 2026 Aquiles Carattino
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License
Privacy Policy