获取git中文件的所有修订版

Dog*_*ert 5 unix git

我有一个git存储库,里面有多个文件.

我需要得到一个特定文件的所有版本(没有差别)foo.bar,并将其存储为喜欢的东西0001-{date}-{sha}-foo.bar,0002-{date}-{sha}-foo.bar等在一个新的文件夹.

我怎样才能做到这一点?

Wil*_*ell 7

假设您想要作者日期,并且unix时间戳是可以的:

i=0
git log --reverse --format=%H\ %at $file |
while read hash date; do
  git show $hash:$file > $(dirname $file)/$i-$hash-$date-$(basename $file)
  : $((i += 1))
done

应该做你想做的事.如果您想要不同的日期,请在说明符处更改%,但unix时间戳很好,因为您不必处理名称中的空格.显然,如果你愿意,有办法解决这个问题.