Skip to content
Advertisement

PHP: Get all Commit Messages of Remote Repository

I’m trying to parse all the Git Commit Messages of a Remote Repository. So far I have:

exec('git rev-parse --verify HEAD 2> /dev/null', $output);
$hash = $output[0];
exec("git show $hash", $output);
var_dump(exec('git fetch --all; git log origin/master', $output));

When I use the same commands in console it works just fine, showing me all the Commit Messages.

However once I try it in PHP, it only shows me “Initial Commit” and nothing else.

Advertisement

Answer

The output you need to dump is not returned by the exec() function, it’s in $output.

Instead of your last line, try

exec('git fetch --all; git log origin/master', $output);
var_dump($output);
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement