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 modification time.
Is there a way I can tell Git to do this?
(As an example, when working on a large project, I made some changes to configure.ac, found out that autotools doesn’t work on my system, and wanted to restore configure.ac‘s to its original contents and modification time so that make doesn’t try to update configure with my broken autotools.)
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 timestamps were applied to files checked out from ‘old’ commits:
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.acto reset the modification time of onlyconfigure.ac, (or bring configure forward in time withtouch configure).Actually, this is an easy “exercise for the reader” if you want to practice reading C code. The function that changes timestamps is
utimeorutimes. Search the code for uses of those functions (hint:git grep utimein a git.git clone). If there are some uses, analyze the code paths to find out when it updates timestamps.