這個工具應該訣竅。它將作者的時間和時間更新爲提交者的時間。它將用作結賬鉤子。
用DEBUG = 1運行,讓它告訴你它到底在做什麼。
請注意,它不使用模塊,只是基本的Perl,所以應該在任何地方運行。
#!/usr/bin/perl
# git-utimes: update file times to last commit on them
# Tom Christiansen <[email protected]>
use v5.10; # for pipe open on a list
use strict;
use warnings;
use constant DEBUG => !!$ENV{DEBUG};
my @gitlog = (
qw[git log --name-only],
qq[--format=format:"%s" %ct %at],
@ARGV,
);
open(GITLOG, "-|", @gitlog) || die "$0: Cannot open pipe from `@gitlog`: $!\n";
our $Oops = 0;
our %Seen;
$/ = "";
while (<GITLOG>) {
next if /^"Merge branch/;
s/^"(.*)" // || die;
my $msg = $1;
s/^(\d+) (\d+)\n//gm || die;
my @times = ($1, $2); # last one, others are merges
for my $file (split /\R/) { # I'll kill you if you put vertical whitespace in our paths
next if $Seen{$file}++;
next if !-f $file; # no longer here
printf "atime=%s mtime=%s %s -- %s\n",
(map { scalar localtime $_ } @times),
$file, $msg,
if DEBUG;
unless (utime @times, $file) {
print STDERR "$0: Couldn't reset utimes on $file: $!\n";
$Oops++;
}
}
}
exit $Oops;
可能重複[什麼是相當於使用提交時間的git?](http://stackoverflow.com/questions/1964470/whats-the-equivalent-of-use-commit-times-for-git ) – MestreLion 2014-08-14 20:58:39
還有:http://stackoverflow.com/questions/2179722/checking-out-file-with-original-create-modified-timestamps – MestreLion 2014-08-14 20:59:15
沒有腳本在這裏爲我工作;這個答案在鏈接到類似的問題是什麼:http://stackoverflow.com/a/30143117/841830 – 2017-01-22 14:28:28