PhpGit - ๐ช Git wrapper and feature extension library written in PHP.
The project is forked from https://github.com/kzykhys/PHPGit
Features
- Quick run git commands, eg:
clone,add,commit,merge
- Git repo info fetch:
status
branch
remote
- Generate changelog by git log
Requirements
- PHP 8.1+
- Git
Method 1: directly composer require
composer require phppkg/phpgit
Method 2: update composer.json
Update your composer.json and run composer update
{
"require": {
"phppkg/phpgit": "dev-master"
}
}
<?php
require __DIR__ . '/vendor/autoload.php';
$git = PhpGit\Git::new();
$git->clone('https://github.com/phppkg/PhpGit.git', '/path/to/repo');
$git->setRepository('/path/to/repo');
$git->remote->add('production', 'git://example.com/your/repo.git');
$git->add('README.md');
$git->commit('Adds README.md');
$git->checkout('release');
$git->merge('master');
$git->push();
$git->push('production', 'release');
$git->tag->create('v1.0.1', 'release');
foreach ($git->tree('release') as $object) {
if ($object['type'] == 'blob') {
echo $git->show($object['file']);
}
}
$repo = PhpGit\Repo::new('/path/to/repo');
$remotes = $repo->getRemotes();
$url = $repo->getRemoteUrl('origin');
$info = $repo->getRemoteInfo('origin');
var_dump($info);
Output:
object(PhpGit\Info\RemoteInfo)#35 (8) {
["type"]=> string(4) "http"
["name"]=> string(6) "origin"
["url"]=> string(34) "https://github.com/phppkg/phpgit.git"
["scheme"]=> string(5) "https"
["host"]=> string(10) "github.com"
["path"]=> string(11) "phppkg/phpgit"
["group"]=> string(4) "ulue"
["repo"]=> string(6) "phpgit"
}
Provide quick generate formatted changelog.
SimpleFormatter
MarkdownFormatter
GithubReleaseFormatter
KeywordFilter
KeywordsFilter
MsgLenFilter
WordsLenFilter
use Toolkit\Cli\Color;
use PhpGit\Changelog\Formatter\GithubReleaseFormatter;
use PhpGit\Changelog\Formatter\SimpleFormatter;
use PhpGit\Changelog\GitChangeLog;
// this is built in log format.
// you can custom format string, but must be set an log parser by $gcl->setLineParser(new YourLineParser);
$logFormat = GitChangeLog::LOG_FMT_HSC;
$oldVersion = 'v0.2.1';
$newVersion = 'HEAD';
// get output by git log cmd:
// `git log v0.2.1...HEAD --reverse --pretty=format:"%H | %s | %cn" --no-merges`
$c = PhpGit\Git::new()->newCmd('log');
$c->add("$oldVersion...$newVersion");
$c->add('--reverse');
$c->addf('--pretty=format:"%s"', $logFormat);
// get repo url
$info = PhpGit\Repo::new()->getRemoteInfo('origin');
$repoUrl = $info->getHttpUrl();
Color::info('repo URL: ' . $repoUrl);
// create object by output.
$gcl = GitChangeLog::new($c->getOutput());
$gcl->setLogFormat($logFormat);
$gcl->setRepoUrl($repoUrl);
// you can set output style. default is markdown.
// can also, you can custom your item formatter
$gcl->setItemFormatter(new GithubReleaseFormatter());
//$gcl->setItemFormatter(new SimpleFormatter());
Color::info('parse logs and generate changelog');
// parse and generate.
$str = $gcl->generate();
echo $str;
Run example php bin/chlog.php
will see:
> git log v0.2.1...HEAD --reverse --pretty=format:"%H | %s | %cn" --no-merges
> git remote -v
[INFO] repo URL:https://github.com/phppkg/phpgit
[INFO] parse logs and generate changelog
### Fixed
- fix get latest tag error on windows https://github.com/phppkg/phpgit/commit/b9892b0ec363e405fcb76b08ea971fb651b4d2dc
### Update
- up: rename package org to phppkg https://github.com/phppkg/phpgit/commit/990e55c6beddf654819c323c2a18d329074399f9
- update some info https://github.com/phppkg/phpgit/commit/"1110de8b5ef0406c837bcd65f607b6f9483c9154
### Feature
- feat: add util for quick generate change log https://github.com/phppkg/phpgit/commit/50962c12d3f16cdbbd8c1f21bc17ff920842365e
- git add
- $git->add(string|array|\Traversable $file, array $options = [])
- git archive
- $git->archive(string $file, string $tree = null, string|array|\Traversable $path = null, array $options = [])
- git branch
- git cat-file
- git checkout
- git clone
- $git->clone(string $repository, string $path = null, array $options = [])
- git commit
- $git->commit(string $message, array $options = [])
- git config
- git describe
- git fetch
- git init
- $git->init(string $path, array $options = [])
- git log
- $git->log(string $revRange = '', string $path = null, array $options = [])
- git merge
- git mv
- $git->mv(string|array|\Iterator $source, string $destination, array $options = [])
- git pull
- $git->pull(string $repository = null, string $refspec = null, array $options = [])
- git push
- $git->push(string $repository = null, string $refspec = null, array $options = [])
- git rebase
- git remote
- $git->remote()
- $git->remote->add(string $name, string $url, array $options = [])
- $git->remote->rename(string $name, string $newName)
- $git->remote->rm(string $name)
- $git->remote->show(string $name)
- $git->remote->prune(string $name = null)
- $git->remote->head(string $name, string $branch = null)
- $git->remote->head->set(string $name, string $branch)
- $git->remote->head->delete(string $name)
- $git->remote->head->remote(string $name)
- $git->remote->branches(string $name, array $branches)
- $git->remote->branches->set(string $name, array $branches)
- $git->remote->branches->add(string $name, array $branches)
- $git->remote->url(string $name, string $newUrl, string $oldUrl = null, array $options = [])
- $git->remote->url->set(string $name, string $newUrl, string $oldUrl = null, array $options = [])
- $git->remote->url->add(string $name, string $newUrl, array $options = [])
- $git->remote->url->delete(string $name, string $url, array $options = [])
- git reset
- $git->reset(string|array|\Traversable $paths, string $commit = null)
- $git->reset->soft(string $commit = null)
- $git->reset->mixed(string $commit = null)
- $git->reset->hard(string $commit = null)
- $git->reset->merge(string $commit = null)
- $git->reset->keep(string $commit = null)
- $git->reset->mode(string $mode, string $commit = null)
- git rm
- git shortlog
- git show
- $git->show(string $object, array $options = [])
- git stash
- $git->stash()
- $git->stash->save(string $message = null, array $options = [])
- $git->stash->lists(array $options = [])
- $git->stash->show(string $stash = null)
- $git->stash->drop(string $stash = null)
- $git->stash->pop(string $stash = null, array $options = [])
- $git->stash->apply(string $stash = null, array $options = [])
- $git->stash->branch(string $name, string $stash = null)
- $git->stash->clear()
- $git->stash->create()
- git status
- $git->status(array $options = [])
- git tag
- git ls-tree
- $git->tree(string $branch = master, string $path = '')
$git->add(string|array|\Traversable $file, array $options = [])
Add file contents to the index
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->add('file.txt');
$git->add('file.txt', ['force' => false, 'ignore-errors' => false);
- force (boolean) Allow adding otherwise ignored files
- ignore-errors (boolean) Do not abort the operation
$git->archive(string $file, string $tree = null, string|array|\Traversable $path = null, array $options = [])
Create an archive of files from a named tree
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->archive('repo.zip', 'master', null, ['format' => 'zip']);
- format (boolean) Format of the resulting archive: tar or zip
- prefix (boolean) Prepend prefix/ to each filename in the archive
Returns an array of both remote-tracking branches and local branches
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$branches = $git->branch();
[
'master' => ['current' => true, 'name' => 'master', 'hash' => 'bf231bb', 'title' => 'Initial Commit'],
'origin/master' => ['current' => false, 'name' => 'origin/master', 'alias' => 'remotes/origin/master']
]
- all (boolean) List both remote-tracking branches and local branches
- remotes (boolean) List the remote-tracking branches
Creates a new branch head named $branch which points to the current HEAD, or $startPoint if given
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->branch->create('bugfix'); // from current HEAD
$git->branch->create('patch-1', 'a092bf7s'); // from commit
$git->branch->create('1.0.x-fix', 'v1.0.2'); // from tag
- force (boolean) Reset $branch to $startPoint if $branch exists already
Move/rename a branch and the corresponding reflog
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->branch->move('bugfix', '2.0');
- force (boolean) Move/rename a branch even if the new branch name already exists
Delete a branch
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->branch->delete('2.0');
The branch must be fully merged in its upstream branch, or in HEAD if no upstream was set with --track or --set-upstream.
- force (boolean) Delete a branch irrespective of its merged status
Returns the contents of blob object
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$contents = $git->cat->blob('e69de29bb2d1d6434b8b29ae775ad8');
Returns the object type identified by $object
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$type = $git->cat->type('e69de29bb2d1d6434b8b29ae775ad8');
Returns the object size identified by $object
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$type = $git->cat->size('e69de29bb2d1d6434b8b29ae775ad8');
Switches branches by updating the index, working tree, and HEAD to reflect the specified branch or commit
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->checkout('develop');
- force (boolean) Proceed even if the index or the working tree differs from HEAD
- merge (boolean) Merges local modification
Create a new branch and checkout
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->checkout->create('patch-1');
$git->checkout->create('patch-2', 'develop');
- force (boolean) Proceed even if the index or the working tree differs from HEAD
Create a new orphan branch, named <new_branch>, started from <start_point> and switch to it
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->checkout->orphan('gh-pages');
- force (boolean) Proceed even if the index or the working tree differs from HEAD
Clone a repository into a new directory
$git = new PhpGit\Git();
$git->clone('https://github.com/kzykhys/PhpGit.git', '/path/to/repo');
- shared (boolean) Starts out without any object of its own
- bare (boolean) Make a bare GIT repository
Record changes to the repository
$git = new PhpGit\Git();
$git->clone('https://github.com/kzykhys/PhpGit.git', '/path/to/repo');
$git->setRepository('/path/to/repo');
$git->add('README.md');
$git->commit('Fixes README.md');
- all (boolean) Stage files that have been modified and deleted
- reuse-message (string) Take an existing commit object, and reuse the log message and the authorship information (including the timestamp) when creating the commit
- squash (string) Construct a commit message for use with rebase --autosquash
- author (string) Override the commit author
- date (string) Override the author date used in the commit
- cleanup (string) Can be one of verbatim, whitespace, strip, and default
- amend (boolean) Used to amend the tip of the current branch
Returns all variables set in config file
- global (boolean) Read or write configuration options for the current user
- system (boolean) Read or write configuration options for all users on the current machine
Set an option
- global (boolean) Read or write configuration options for the current user
- system (boolean) Read or write configuration options for all users on the current machine
Adds a new line to the option without altering any existing values
- global (boolean) Read or write configuration options for the current user
- system (boolean) Read or write configuration options for all users on the current machine
Returns the most recent tag that is reachable from a commit
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->tag->create('v1.0.0');
$git->commit('Fixes #14');
echo $git->describe('HEAD', ['tags' => true]);
v1.0.0-1-g7049efc
- all (boolean) Enables matching any known branch, remote-tracking branch, or lightweight tag
- tags (boolean) Enables matching a lightweight (non-annotated) tag
- always (boolean) Show uniquely abbreviated commit object as fallback
Equivalent to $git->describe($committish, ['tags' => true]);
Fetches named heads or tags from one or more other repositories, along with the objects necessary to complete them
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'git://your/repo.git');
$git->fetch('origin');
- append (boolean) Append ref names and object names of fetched refs to the existing contents of .git/FETCH_HEAD
- keep (boolean) Keep downloaded pack
- prune (boolean) After fetching, remove any remote-tracking branches which no longer exist on the remote
Fetch all remotes
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'git://your/repo.git');
$git->remote->add('release', 'git://your/another_repo.git');
$git->fetch->all();
- append (boolean) Append ref names and object names of fetched refs to the existing contents of .git/FETCH_HEAD
- keep (boolean) Keep downloaded pack
- prune (boolean) After fetching, remove any remote-tracking branches which no longer exist on the remote
Create an empty git repository or reinitialize an existing one
$git = new PhpGit\Git();
$git->init('/path/to/repo1');
$git->init('/path/to/repo2', array('shared' => true, 'bare' => true));
- shared (boolean) Specify that the git repository is to be shared amongst several users
- bare (boolean) Create a bare repository
Returns the commit logs
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$logs = $git->log(array('limit' => 10));
[
0 => [
'hash' => '1a821f3f8483747fd045eb1f5a31c3cc3063b02b',
'name' => 'John Doe',
'email' => '[email protected]',
'date' => 'Fri Jan 17 16:32:49 2014 +0900',
'title' => 'Initial Commit'
],
1 => [
//...
]
]
- limit (integer) Limits the number of commits to show
- skip (integer) Skip number commits before starting to show the commit output
Incorporates changes from the named commits into the current branch
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->merge('1.0');
$git->merge('1.1', 'Merge message', ['strategy' => 'ours']);
- no-ff (boolean) Do not generate a merge commit if the merge resolved as a fast-forward, only update the branch pointer
- rerere-autoupdate (boolean) Allow the rerere mechanism to update the index with the result of auto-conflict resolution if possible
- squash (boolean) Allows you to create a single commit on top of the current branch whose effect is the same as merging another branch
- strategy (string) Use the given merge strategy
- strategy-option (string) Pass merge strategy specific option through to the merge strategy
Abort the merge process and try to reconstruct the pre-merge state
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
try {
$git->merge('dev');
} catch (PhpGit\Exception\GitException $e) {
$git->merge->abort();
}
Move or rename a file, a directory, or a symlink
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->mv('UPGRADE-1.0.md', 'UPGRADE-1.1.md');
- force (boolean) Force renaming or moving of a file even if the target exists
Fetch from and merge with another repository or a local branch
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->pull('origin', 'master');
Update remote refs along with associated objects
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->push('origin', 'master');
Forward-port local commits to the updated upstream head
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->fetch('origin');
$git->rebase('origin/master');
- onto (string) Starting point at which to create the new commits
- no-verify (boolean) Bypasses the pre-rebase hook
- force-rebase (boolean) Force the rebase even if the current branch is a descendant of the commit you are rebasing onto
Restart the rebasing process after having resolved a merge conflict
Abort the rebase operation and reset HEAD to the original branch
Restart the rebasing process by skipping the current patch
Returns an array of existing remotes
$git = new PhpGit\Git();
$git->clone('https://github.com/kzykhys/Text.git', '/path/to/repo');
$git->setRepository('/path/to/repo');
$remotes = $git->remote();
[
'origin' => [
'fetch' => 'https://github.com/kzykhys/Text.git',
'push' => 'https://github.com/kzykhys/Text.git'
]
]
Adds a remote named $name for the repository at $url
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
$git->fetch('origin');
- tags (boolean) With this option,
git fetch <name>
imports every tag from the remote repository - no-tags (boolean) With this option,
git fetch <name>
does not import tags from the remote repository
Rename the remote named $name to $newName
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
$git->remote->rename('origin', 'upstream');
Remove the remote named $name
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
$git->remote->rm('origin');
Gives some information about the remote $name
$git = new PhpGit\Git();
$git->clone('https://github.com/kzykhys/Text.git', '/path/to/repo');
$git->setRepository('/path/to/repo');
echo $git->remote->show('origin');
\* remote origin
Fetch URL: https://github.com/kzykhys/Text.git
Push URL: https://github.com/kzykhys/Text.git
HEAD branch: master
Remote branch:
master tracked
Local branch configured for 'git pull':
master merges with remote master
Local ref configured for 'git push':
master pushes to master (up to date)
Deletes all stale remote-tracking branches under $name
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->prune('origin');
Alias of set()
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
$git->remote->head('origin');
Sets the default branch for the named remote
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
$git->remote->head->set('origin');
Deletes the default branch for the named remote
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
$git->remote->head->delete('origin');
Determine the default branch by querying remote
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
$git->remote->head->remote('origin');
Alias of set()
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
$git->remote->branches('origin', array('master', 'develop'));
Changes the list of branches tracked by the named remote
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
$git->remote->branches->set('origin', array('master', 'develop'));
Adds to the list of branches tracked by the named remote
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
$git->remote->branches->add('origin', array('master', 'develop'));
Alias of set()
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
$git->remote->url('origin', 'https://github.com/text/Text.git');
- push (boolean) Push URLs are manipulated instead of fetch URLs
Sets the URL remote to $newUrl
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
$git->remote->url->set('origin', 'https://github.com/text/Text.git');
- push (boolean) Push URLs are manipulated instead of fetch URLs
Adds new URL to remote
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
$git->remote->url->add('origin', 'https://github.com/text/Text.git');
- push (boolean) Push URLs are manipulated instead of fetch URLs
Deletes all URLs matching regex $url
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
$git->remote->url->delete('origin', 'https://github.com');
- push (boolean) Push URLs are manipulated instead of fetch URLs
Resets the index entries for all $paths to their state at $commit
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->reset();
Resets the current branch head to $commit
Does not touch the index file nor the working tree at all (but resets the head to $commit, just like all modes do). This leaves all your changed files "Changes to be committed", as git status would put it.
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->reset->soft();
Resets the current branch head to $commit
Resets the index but not the working tree (i.e., the changed files are preserved but not marked for commit) and reports what has not been updated. This is the default action.
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->reset->mixed();
Resets the current branch head to $commit
Resets the index and working tree. Any changes to tracked files in the working tree since $commit are discarded
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->reset->hard();
Resets the current branch head to $commit
Resets the index and updates the files in the working tree that are different between $commit and HEAD, but keeps those which are different between the index and working tree (i.e. which have changes which have not been added). If a file that is different between $commit and the index has unstaged changes, reset is aborted
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->reset->merge();
Resets the current branch head to $commit
Resets index entries and updates files in the working tree that are different between $commit and HEAD. If a file that is different between $commit and HEAD has local changes, reset is aborted.
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->reset->keep();
Resets the current branch head to $commit
Possibly updates the index (resetting it to the tree of $commit) and the working tree depending on $mode
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->reset->mode('hard');
Remove files from the working tree and from the index
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->rm('CHANGELOG-1.0-1.1.txt', ['force' => true]);
- force (boolean) Override the up-to-date check
- cached (boolean) Unstage and remove paths only from the index
- recursive (boolean) Allow recursive removal when a leading directory name is given
Equivalent to $git->rm($file, ['cached' => true]);
- force (boolean) Override the up-to-date check
- recursive (boolean) Allow recursive removal when a leading directory name is given
Summarize 'git log' output
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$shortlog = $git->shortlog();
[
'John Doe <[email protected]>' => [
0 => ['commit' => '589de67', 'date' => new \DateTime('2014-02-10 12:56:15 +0300'), 'subject' => 'Update README'],
1 => ['commit' => '589de67', 'date' => new \DateTime('2014-02-15 12:56:15 +0300'), 'subject' => 'Update README'],
],
//...
]
Suppress commit description and provide a commit count summary only
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$shortlog = $git->shortlog->summary();
[
'John Doe <[email protected]>' => 153,
//...
]
Shows one or more objects (blobs, trees, tags and commits)
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
echo $git->show('3ddee587e209661c8265d5bfd0df999836f6dfa2');
- format (string) Pretty-print the contents of the commit logs in a given format, where can be one of oneline, short, medium, full, fuller, email, raw and format:
- abbrev-commit (boolean) Instead of showing the full 40-byte hexadecimal commit object name, show only a partial prefix
Save your local modifications to a new stash, and run git reset --hard to revert them
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->stash();
Save your local modifications to a new stash, and run git reset --hard to revert them.
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->stash->save('My stash');
Returns the stashes that you currently have
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$stashes = $git->stash->lists();
[
0 => ['branch' => 'master', 'message' => '0e2f473 Fixes README.md'],
1 => ['branch' => 'master', 'message' => 'ce1ddde Initial commit'],
]
Show the changes recorded in the stash as a diff between the stashed state and its original parent
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
echo $git->stash->show('stash@{0}');
REAMDE.md | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
Remove a single stashed state from the stash list
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->stash->drop('stash@{0}');
Remove a single stashed state from the stash list and apply it on top of the current working tree state
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->stash->pop('stash@{0}');
Like pop, but do not remove the state from the stash list
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->stash->apply('stash@{0}');
Creates and checks out a new branch named starting from the commit at which the was originally created, applies the changes recorded in to the new working tree and index
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->stash->branch('hotfix', 'stash@{0}');
Remove all the stashed states
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->stash->clear();
Create a stash (which is a regular commit object) and return its object name, without storing it anywhere in the ref namespace
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$commit = $git->stash->create();
877316ea6f95c43b7ccc2c2a362eeedfa78b597d
Returns the working tree status
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$status = $git->status();
- StatusCommand::UNMODIFIED [=' '] unmodified
- StatusCommand::MODIFIED [='M'] modified
- StatusCommand::ADDED [='A'] added
- StatusCommand::DELETED [='D'] deleted
- StatusCommand::RENAMED [='R'] renamed
- StatusCommand::COPIED [='C'] copied
- StatusCommand::UPDATED_BUT_UNMERGED [='U'] updated but unmerged
- StatusCommand::UNTRACKED [='?'] untracked
- StatusCommand::IGNORED [='!'] ignored
[
'branch' => 'master',
'changes' => [
['file' => 'item1.txt', 'index' => 'A', 'work_tree' => 'M'],
['file' => 'item2.txt', 'index' => 'A', 'work_tree' => ' '],
['file' => 'item3.txt', 'index' => '?', 'work_tree' => '?'],
]
]
- ignored (boolean) Show ignored files as well
Returns an array of tags
$git = new PhpGit\Git();
$git->clone('https://github.com/kzykhys/PhpGit.git', '/path/to/repo');
$git->setRepository('/path/to/repo');
$tags = $git->tag();
['v1.0.0', 'v1.0.1', 'v1.0.2']
Creates a tag object
$git = new PhpGit\Git();
$git->setRepository('/path/to/repo');
$git->tag->create('v1.0.0');
- annotate (boolean) Make an unsigned, annotated tag object
- sign (boolean) Make a GPG-signed tag, using the default e-mail addressโs key
- force (boolean) Replace an existing tag with the given name (instead of failing)
Delete existing tags with the given names
Verify the gpg signature of the given tag names
Returns the contents of a tree object
$git = new PhpGit\Git();
$git->clone('https://github.com/kzykhys/PhpGit.git', '/path/to/repo');
$git->setRepository('/path/to/repo');
$tree = $git->tree('master');
[
['mode' => '100644', 'type' => 'blob', 'hash' => '1f100ce9855b66111d34b9807e47a73a9e7359f3', 'file' => '.gitignore', 'sort' => '2:.gitignore'],
['mode' => '100644', 'type' => 'blob', 'hash' => 'e0bfe494537037451b09c32636c8c2c9795c05c0', 'file' => '.travis.yml', 'sort' => '2:.travis.yml'],
['mode' => '040000', 'type' => 'tree', 'hash' => '8d5438e79f77cd72de80c49a413f4edde1f3e291', 'file' => 'bin', 'sort' => '1:.bin'],
]
The MIT License
Developed by Kazuyuki Hayashi (@kzykhys), Maintained by @inhere