Git 存档保存时间

Git archive preserve time

我的 Git 存储库中有一些文件:

...
-rw-r--r--  1 dimti dimti 11489 мар  2 21:54 wp-settings.php
...

执行命令后

git archive --format=tar HEAD > repo.tar

我在 tar 存档中获取我的文件,但修改时间是错误的:

-rw-r--r--  1 dimti dimti 11115 мар  5 21:55 wp-settings.php

如何对 Git 存档说 - 保留 tar 存档中文件的修改时间?

您可以先尝试标记它,以便使用该标记,或者使用提交 ID

git archive man 页面提到:

git archive behaves differently when given a tree ID versus when given a commit ID or tag ID.

  • In the first case (tree ID like HEAD) the current time is used as the modification time of each file in the archive.
  • In the latter case (commit ID or tag ID) the commit time as recorded in the referenced commit object is used instead.

所以在你的情况下(使用“How to retrieve the hash for the current commit in Git?”):

git archive --format=tar $(git rev-parse HEAD) > repo.tar