get the last modification data of a file in git repo

前端 未结 3 2187
没有蜡笔的小新
没有蜡笔的小新 2021-02-04 06:59

Im trying to find the command to get the last modified date of a file in a local git repo.

Created the repo and have done one commit. Had to edit one file and will commi

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-04 07:18

    Git doesn't record the last modification date, only the commit/author dates for a all commit (which can include more than one file).

    You would need to run a script in order to amend a commit with the last modification date of a particular file (not very useful if said commit has more than one file in it).
    See an example at "Git: Change timestamp after pushing".

    Another option would be to record those timestamp in a separate file, and amend your commit that way: see "What's the equivalent of use-commit-times for git?".

    That includes:

    1. mtimestore - core script providing 3 options:
      • -a (save all - for initialization in already existing repo (works with git-versed files)),
      • -s (to save staged changes), and
      • -r to restore them.
    2. pre-commit hook
    3. post-checkout hook

    Incidentally, this is the post where I explained 5 years ago why Git doesn't record timestamps.

提交回复
热议问题