Restore a file's modification time in Git

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

    The following shell script should work on any POSIX-compatible system to set the modification and access timestamp of all tracked files (and directories). The only downside I could determine yet is that it is quite slow but that's fine for my use case (setting the right dates when producing release archives).

    rev=HEAD
    for f in $(git ls-tree -r -t --full-name --name-only "$rev") ; do
        touch -d $(git log --pretty=format:%cI -1 "$rev" -- "$f") "$f";
    done
    

提交回复
热议问题