Write git to report version information in the application footer

I use git for version control for this one mysql / php project, and I have virtual hosts configured in Apache, where the default source / main website (port 80) and another virtual host, with different ports (8081, 8082 , 8083, etc.) for each folder of the working copy of dev (so that we can view each other on the fly) ... using git (hooks?),

how can I configure it so that every time someone commits and pushes it, it writes information about the human-readable version (time stamp, committer, comment, repository, branch, etc.) into the HTML file? I hope to drop this information in the footer of each page, to make it even easier to keep track of who is working / copying, which we are currently viewing.

+5
source share
1 answer

You can add this to the footer if you have access to the exec() function:

 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>'; 

Gives you a result something like this:

 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 ) 
+3
source

Source: https://habr.com/ru/post/1243796/


All Articles