I want to see the date of git creation (date of first commit where they were added) of all the files on a specified directory.
`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.
And Git doesn't preserve timestamps—meaning, when I checkout a branch with an earlier version of a file, that file's timestamp now matches the time now (when I checked out the branch) and not the time of the last commit in which the file changed.
Git stores the complete history of your files for a project in a special directory (a.k.a. a folder) called a repository, or repo. This repo is usually in a hidden folder called . git sitting next to your files.
I'll break my solution into steps.
$ git ls-files
This returns a list of relative paths of all files in the repository.
$ git rev-list HEAD <file> | tail -n 1
This will return a list of all parentless commits for a given file, in reverse chronological order. The last one is the SHA-1 hash of the first commit for the given file.
You can verify this by running git log --raw <hash>
. You should see something like:
commit <commit_hash>
Author: Susy Q <[email protected]>
Date: Wed Aug 24 12:36:34 2011 -0400
Add new module 'example.py'
:000000 100644 0000000... <hash>... A example.py
$ git show -s --format="%ci" <hash>
#!/bin/bash
for file in $(git ls-files)
do
HASH=$(git rev-list HEAD "$file" | tail -n 1)
DATE=$(git show -s --format="%ci" $HASH --)
printf "%-35s %s\n %s\n" "$file" $HASH: "$DATE"
done
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