Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Git store the file creation time?

Tags:

git

Let's say I created a project and pushed it to GitHub. When someone clones the project, can they see the file creation time of each file in the project?

like image 488
undefined Avatar asked Dec 22 '22 17:12

undefined


1 Answers

They can see the time when a file was added to the repository, via the commit date.

They cannot see the "file creation" or "file modification" timestamps of the file in your local filesystem.

Example

$ git init
Initialized empty Git repository in /tmp/tmp.t4KdOYhQGr/.git/
$ echo bla >file.txt
$ git add file.txt
$ git commit -m 'Added a file'
[master (root-commit) 26b458c] Added a file
 1 file changed, 1 insertion(+)
 create mode 100644 file.txt

Let's look at the commit object:

$ git cat-file -p 26b458c
tree 80717c30ff0d58d079079d2f4d38441035093c49
author mkrieger1 <[email protected]> 1590570496 +0200
committer mkrieger1 <[email protected]> 1590570496 +0200

Added a file

It contains:

  • A reference to a tree object
  • An author with name, email, and timestamp
  • A committer with name, email, and timestamp

These timestamps specify when a commit was first authored, and when it was committed (can be different, e.g. in case of cherry-picking, but here it's the same).

Let's look at the tree object referenced by the commit:

$ git cat-file -p 80717c30ff0d58d079079d2f4d38441035093c49
100644 blob a7f8d9e5dcf3a68fdd2bfb727cde12029875260b    file.txt

It contains a list of blob objects (only a single one in this case), with for each:

  • File permissions
  • A reference to the blob data
  • The name of the blob in the tree

It doesn't contain any timestamps at all. Let's look at the blob object referenced by the tree:

$ git cat-file -p a7f8d9e5dcf3a68fdd2bfb727cde12029875260b
bla

It's just the bare file contents, no timestamps here, either.

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.

like image 60
mkrieger1 Avatar answered Jan 10 '23 01:01

mkrieger1