GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - gitonomy/gitlib: Library for accessing Git repositories with PHP

BranchesTags
Open more actions menu

Latest commit

 

History

435 Commits
435 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
doc
doc
 
 
src/Gitonomy/Git
src/Gitonomy/Git
 
 
tests
tests
 
 
tools
tools
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
.php-cs-fixer.php
.php-cs-fixer.php
 
 
CHANGELOG.md
CHANGELOG.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
UPGRADE-2.0.md
UPGRADE-2.0.md
 
 
benchmark.php
benchmark.php
 
 
castor.php
castor.php
 
 
composer.json
composer.json
 
 
phpstan.neon
phpstan.neon
 
 
phpunit.xml.dist
phpunit.xml.dist
 
 
test-git-versions.php
test-git-versions.php
 
 
zensical.toml
zensical.toml
 
 

Repository files navigation

gitlib

Access git repositories from PHP 8.4+, through the git binary or libgit2.

use Gitonomy\Git\Repository;

$repository = new Repository('/path/to/repository');

// The last 5 commits of main that changed src/
foreach ($repository->getLog('main', 'src', limit: 5) as $commit) {
    echo $commit->getShortHash().' '.$commit->getSubjectMessage().PHP_EOL;
}

// The files the last commit changed
foreach ($repository->getHeadCommit()->getDiff()->getFiles() as $file) {
    echo $file->getName().': +'.$file->getAdditions().' -'.$file->getDeletions().PHP_EOL;
}

// Who wrote the first lines of README.md
foreach ($repository->getBlame('main', 'README.md', 1, 3)->getLines() as $line) {
    echo $line->getCommit()->getAuthorName().': '.$line->getContent().PHP_EOL;
}

The documentation is at gitonomy.github.io/gitlib.

What it does

  • Open a bare repository, a working tree, a linked worktree or a submodule, or create one: init, clone, mirror. See Opening a repository and Creating repositories.
  • Read commits, logs, trees, blobs, diffs, blames, branches and tags, as PHP objects.
  • Change the working copy: checkout, new branches, merges, and the diffs of what is pending or staged. See Working copy.
  • Manage the hooks of a repository: see Hooks.
  • Run any other git command: see Running git commands.

Two drivers

Repository runs git through a driver, its last argument:

  • CliDriver, the default, runs the git binary, 1.8.4 or later, and needs nothing else;
  • LibGit2Driver, experimental, runs libgit2 1.9 in-process, through PHP's FFI extension. It is faster for many small reads in a long-running process, and slower on long histories, like blames: see "Choosing a driver".
use Gitonomy\Git\Driver\Ffi\LibGit2Driver;
use Gitonomy\Git\Repository;

$repository = new Repository('/path/to/repository', driver: new LibGit2Driver());

Installation

composer require gitonomy/gitlib

Upgrading from 1.x? Read UPGRADE-2.0.md and the changelog.

Documentation

  • Opening a repository: paths, drivers, errors, git configuration
  • Creating repositories
  • Revisions
  • Commits
  • Log
  • Trees
  • Blobs
  • Diffs
  • Blame
  • Tags and branches
  • Branches
  • Working copy
  • Hooks

For Enterprise

Available as part of the Tidelift Subscription

The maintainers of gitonomy/gitlib and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.

License

gitlib is released under the MIT license.

About

Library for accessing Git repositories with PHP

gitonomy.github.io/gitlib/

Topics

hacktoberfest

Resources

Readme
MIT license

Code of conduct

Code of conduct

Contributing

Contributing

Security policy

Security policy
Activity
Custom properties

Stars

466 stars

Watchers

22 watching

Forks

73 forks
Report repository

Releases

Sponsor this project

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.