Restore a file's modification time in Git

后端 未结 9 1520
猫巷女王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:45

    Restore the modificaton time of a list of files to the author date of the their last commit with

    gitmtim(){ local f;for f;do touch -d @0`git log --pretty=%at -n1 -- "$f"` "$f"; done;}; gitmtim configure.ac
    

    It will not change directories recursively, though.

    If you want to change a whole working tree, e.g. after a fresh clone or checkout, you may try

    git log --pretty=%at --name-status --reverse | perl -ane '($x,$f)=@F;next if !$x;$t=$x,next if !defined($f)||$s{$f};$s{$f}=utime($t,$t,$f),next if $x=~/[AM]/;'
    

    NB: I grepped for utime in builtin/clone.c and got no matches.

提交回复
热议问题