-1

I'm trying to get a creation and a modified time stamp for a file from git

Currently I'm using

# get creation date (date file was first checked into git)
git log --format="%cd" --date=unix --diff-filter=A path/to/file

# get modified data (last time file was commited to git)
git log --format="%cd" --date=unix --max-count=1 path/to/file

But, I'm getting different times on the CI vs locally.

locally the times are

1640113243
1664468001

but on the CI they are

1664476473
1664476473

They shouldn't be the same (the file was created months before the last modification) AND they need to match the local results

Any idea what I'm doing wrong or how to get this info in a way that the dates both locally and on the CI match?

gman
  • 100,619
  • 31
  • 269
  • 393
  • Are the commits involved (creation of the file, last modificarion of the file) the same in both repos/branches? – eftshift0 Sep 29 '22 at 18:54
  • 2
    Print the commit hash as part of your output and check if you are looking at the correct commit(s). – knittl Sep 29 '22 at 18:55

1 Answers1

-1

The issue was apparently only getting a depth of 1 when checking out the repo. Setting it to get the entire history fixes it. The new dates on the CI are

1640113243
1664468001

Getting the entire history seems kind of a waste. Are there any optimizations?


Update: apparently you can checkout a repo just getting the history but not the actual file data

https://stackoverflow.com/a/60952814/128511

gman
  • 100,619
  • 31
  • 269
  • 393
  • If you are querying the history (and you are with `git log`), you must have the history. There's no way around it. – knittl Sep 29 '22 at 18:56
  • @knittl , it's certainly theoretically possible to only get the meta data and not require getting the actual content of the files. I'm not saying git supports that option, no idea, but it would theoretically be possible to be able to only get the log info itself as an optimization. – gman Sep 29 '22 at 18:58
  • But the log is defined by the commits and the commits are defined by their meta data and trees. And the trees are, well, defined by their file names and file contents. – knittl Sep 29 '22 at 18:59
  • 1
    https://stackoverflow.com/a/60952814/128511 – gman Sep 29 '22 at 20:13