0

I am seeing that for a particular commit, git is giving different time stamp values for different commands.

$ git show -s --format="%ci" ee9bb
2019-09-09 17:50:43 +0530

The above command shows time value as 17:50:43

While the below commands show time value as 17:24:01

$ git show -s  ee9bb
commit ee9bb706c8fcc329fac4acf69ad6b684f1069170
Author: itsvamshers <itsvamshers@gmail.com>
Date:   Mon Sep 9 17:24:01 2019 +0530

    fixed country null issue


$ git log ee9bb
commit ee9bb706c8fcc329fac4acf69ad6b684f1069170
Author: itsvamshers <itsvamshers@gmail.com>
Date:   Mon Sep 9 17:24:01 2019 +0530

Could anyone explain why this is the case. And which one should I consider.

samshers
  • 1
  • 6
  • 37
  • 84

1 Answers1

2

Pay close attention to the specific details of %ci in the git log documentation (here is a direct link to %ci, but it might fail over time):

%ci
committer date, ISO 8601-like format

Now look at the %ai description:

%ai
author date, ISO 8601-like format

One uses the word committer, the other uses the word author.

There are two dates-and-time-stamps in every commit!

%ci prints the committer date and time stamp.

%ai prints the author date and time stamp.

The default git log output uses the author date, which is why %ci is showing you a different date.

Note that a bit higher up, the PRETTY FORMATS section describes keyword formats that you can get with --pretty=fuller for instance. The fuller format includes both date-and-time-stamps.

... which one should I consider

Both, or neither. Both dates can be spoofed, accidentally or intentionally. Use one or both as indications, or hints, rather than absolute guarantees.

In general, if you copy an existing commit to a new commit, Git will—at least by default—preserve the author date but set you, and now, as the committer and committer-date. Since git cherry-pick copies an existing commit, this happens for cherry-pick. Since git rebase is largely an automated series of cherry-pick operations, this tends to happen with rebase as well.

torek
  • 448,244
  • 59
  • 642
  • 775
  • if i desire to set the committer and committer date back to author and author date, (for a commit that is being made or **already made**) what command do i have to use. – samshers Sep 16 '19 at 12:46
  • @samshers: there is no separate command for that. To make that happen, set the `GIT_COMMITTER_*` environment variables. In particular if `GIT_COMMITTER_DATE` is set to something Git can parse as a date, that is the date that Git will set as the committer date. If there is some existing commit with an author date, you can use that commit's author date to set `GIT_COMMITTER_DATE` for the duration of your `git commit` or `git commit-tree` command. If you're using rebase, you'll have to take the rebase apart into individual commits to set each committer date. – torek Sep 16 '19 at 15:26
  • Or, of course, you can set *both* the `GIT_AUTHOR_DATE` and `GIT_COMMITTER_DATE` variables to two fixed values, so that each new commit you make always has a fixed date-and-time stamp. That is, if you spoof every date (say, make every commit on April Fool's Day of some particular year), you'll always know what to set the dates to in any future commit too. – torek Sep 16 '19 at 15:27