在app的页脚中编写git commit版本信息

cra*_*oty 5 php mysql git

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

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

Pit*_*ate 3

只要您有权访问该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>';
Run Code Online (Sandbox Code Playgroud)

会给你一个类似这样的输出:

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
)
Run Code Online (Sandbox Code Playgroud)