Search code examples
gitgithubcommitgit-commitgit-push

Git local commit timestamp when pushed


I have a simple question. I am working on a feature locally and have made numerous commits without pushing them yet. Once I push these commits, will they have the timestamp (seen in GitHub) when the commit was made locally or rather the timestamp when it was pushed?


Solution

  • The entire text/data of any commit—or any Git object, in fact—is strictly read-only from the point the commit is made. This is because its true name is its hash ID, which is produced by running a crytographically secure hash function over its contents (including the internal Git object header, which has the fortunate side effect of defeating certain known SHA-1 collisions).

    Each commit has two timestamps, one for author-date and one for committer-date. The git commit command normally sets both of these to "now" at the time you run git commit. They are part of the commit data (specifically, part of the metadata that makes up the commit object itself) so from the moment you actually form the commit, these two values can never be changed.

    The git log command normally shows you the author date (only); add --pretty=fuller to see both.

    Since no commit can ever be changed, the commits you send elsewhere, that continue to use the same hash ID as your commits, will continue to have their original data.