在应用的页脚中写入 Git 提交版本信息


write git commit version info in app's footer

我正在使用 git 对这个 mysql/php 项目进行版本控制,我在 Apache 中设置了虚拟主机,其中 origin/master 是默认网站(端口 80)和一个不同的虚拟主机,每个开发人员的工作副本文件夹都有不同的端口(8081、8082、8083 等)(因此我们可以即时查看彼此的工作)...使用 git(钩子?

我如何设置它,以便每次有人提交和推送时,它都会将人类可读的版本信息(时间戳,提交者,评论,存储库,分支等)写入HTML文件?我希望将这些信息放在每个页面的页脚中,以便更容易跟踪我们在给定时间正在查看谁的作品/副本。

只要您有权访问 exec() 函数,就可以将其添加到页脚:

exec('git branch | sed -n "/'* /s///p"', $output);
exec('git --no-pager show --summary', $output2);
$current_commit = [
    'branch' => $output[0],
    'commit' => array_shift($output2),
    'author' => array_shift($output2),
    'date' => array_shift($output2),
    'message' => implode('', $output2),
];
echo '<pre>' . print_r($current_commit,true) . '</pre>';

会给你一个这样的输出:

Array
(
    [branch] => master
    [commit] => commit 12345f424909eda4db1f7a811eb9d3a7e7112345
    [author] => Author: Test Tester <test@test.com>
    [date] => Date:   Thu Feb 11 14:13:51 2016 -0500
    [message] =>     small update
)