peej/git

一个用于Git的OO包装器,允许将Git仓库当作文件系统或数据库使用。

dev-master 2015-05-03 20:17 UTC

This package is not auto-updated.

Last update: 2024-09-14 13:02:27 UTC


README

一个用于Git的OO包装器,允许将Git仓库当作文件系统或数据库使用。

直接通过Git二进制与Git仓库通信,不需要工作副本或写入磁盘文件,因此也可以与裸仓库一起使用。

安装

通过Composer安装,将peej/git作为依赖项添加到项目的composer.json文件中。

{
    "require": {
        "peej/git": "1.0.*"
    }
}

要求

已安装git的系统,预期其在命令路径中。

使用

$repo = new Git\Repo('/tmp/myrepo.git');

// get head commit message
echo $repo->commit()->message;

// get a file from the head
echo $repo->file('mydir/myfile.txt');

// get the latest commit the file was mentioned in
$commit = $repo->file('mydir/myfile.txt')->history[0];

// get a tree for a given path
$tree = $repo->tree('mydir');
echo $tree['myfile.txt'];

// stage a file edit
$repo->update('mydir/myfile.txt', 'new content');

// create a new commit
$repo->save('commit message');