如何向文件添加提交日期/时间

How to add a commit date / time to a file

我在 GitHub 有一个存储库并用 TortoiseGit 更新它。

我不想在每次提交/推送时都创建版本号。但我想在自动提交之前将日期/时间插入 Readme.md 文件。

这可能吗?

您可以在 pre-commit 挂钩中执行此操作,放置以下文件,修改位于 /.git/hooks/pre-commit.sample 中的 .sample 文件。并将其重命名为 pre-commit.

像这样

   #!/bin/sh
   #
   # An example hook script to verify what is about to be committed.
   # Called by "git commit" with no arguments
   # blah...
   date >> README.md
   git add README.md
   echo "Updated the time in README"
   exit 0

因此每次使用 git commit 进行提交时,README.md 文件将随时间更新。 P.S:您可以使用 sed 改进 date 命令来更新时间,例如。这里只是在你每次提交时更新它。 此外,这仅在您使用 GIT BASH 桌面应用程序时有效。