Restore a file's modification time in Git

后端 未结 9 1561
猫巷女王i
猫巷女王i 2020-11-29 01:13

I understand the default Git behaviour of updating the modification time every time it changes a file, but there are times when I want to restore a file\'s original modifica

9条回答
  •  情书的邮戳
    2020-11-29 01:40

    Git does not do this. Like your linked FAQ says, it would break using timestamp-based dependency analysis tools like make.

    Think about what would happen if old time stamps were applied to files checked out from ‘old’ commits:

    • make from a clean directory works fine
    • checkout an older branch/tag/commit (the files would have timestamps older than the build products now!)
    • make now does nothing because all the build products are newer than their dependencies

    But, if you really want it, all the information is there. You could write your own tool to do it.

    In your case, just use something like touch -r configure configure.ac to reset the modification time of only configure.ac, (or bring configure forward in time with touch configure).


    Actually this is an easy “exercise for the reader” if you want to practice reading C code. The function that changes timestamps is utime or utimes. Search the code for uses of those functions (hint: git grep utime in a git.git clone). If there are some uses, analyze the code paths to find out when it updates timestamps.

提交回复
热议问题