Is there a simple Git command to determine the "creation date" of a file in a repository, i.e. the date it was first added?
It would be best if it can determine this even through file renames/moves. I'd like it to be a computer-readable one-line output; it may be that I haven't figured out the correct git log <fname>
options to do this.
You can show the "creation date" that is stored for files in the Windows Explorer easily: Switch Windows Explorer to column view, right click a column header and and in the context menu that pops up select "Creation Date" for enabling the additional column. Note that this setting is folder-specific.
Git file History provides information about the commit history associated with a file. To use it: Go to your project's Repository > Files. In the upper right corner, select History.
Conclusion. The only timestamps that are stored in a Git repository are the "author" and "committer" dates in the commit objects. The tree and blob objects do not contain any timestamps. There is no timestamp information about the files in the local filesystem contained in the Git repository.
`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.
git log --format=%aD <FILE> | tail -1
With this command you can out all date about this file and extract the last
The native solution:
git log --diff-filter=A --follow --format=%aD -1 -- <fname>
It gives the last "creation date" of a file in a repository, and does it regardless of file renames/moves.
-1
is synonym to --max-count=1
and it limits the number of commits to output (to be not more than one in our case).
This limit is needed since a file can be added more than once. For example, it can be added, then removed, then added again. In such case --diff-filter=A
will produce several lines for this file.
To get the first creation date in the first line we should use --reverse
option without limitation (since limit is applied before ordering).
git log --diff-filter=A --follow --format=%aI --reverse -- <fname> | head -1
%aI
gives author date in the strict ISO 8601 format (e.g. 2009-06-03T07:08:51-07:00
).
But this command doesn't work properly due to the known bug in Git (see "--follow is ignored when used with --reverse" conversation in git maillist). So, we are forced to use some work around for awhile to get the first creation date. E.g.:
git log --diff-filter=A --follow --format=%aI -- <fname> | tail -1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With