Skip to content

Latest commit

 

History

History
212 lines (121 loc) · 3.33 KB

git_index_command.md

File metadata and controls

212 lines (121 loc) · 3.33 KB

Git Index: (git add, git reset, git rm, ...)

Use the interface: ArtARTs36\GitHandler\Contracts\Commands\GitIndexCommand


Create Instance

use \ArtARTs36\GitHandler\Factory\LocalGitFactory;

$command = (new LocalGitFactory())->factory(__DIR__)->index();

Features:

* Add file/files to git index

Method Signature:

public function add(string|string[] $file, bool $force = false): bool;

Equals Git Command:

git add $file

git add $file $file $file

Example:

use \ArtARTs36\GitHandler\Factory\LocalGitFactory;

(new LocalGitFactory())->factory(__DIR__)->index()->add('file-test', true);

* Remove file/files from git index

Method Signature:

public function remove(string|string[] $files, bool $force = false): void;

Equals Git Command:

git rm $file

git rm $file1 $file2 ...

Example:

use \ArtARTs36\GitHandler\Factory\LocalGitFactory;

(new LocalGitFactory())->factory(__DIR__)->index()->remove('files-test', true);

* Remove cached file/files from git index

Method Signature:

public function removeCached(string|string[] $files, bool $force = false): void;

Equals Git Command:

git rm --cached $file

git rm --cached $file1 $file2 ...

Example:

use \ArtARTs36\GitHandler\Factory\LocalGitFactory;

(new LocalGitFactory())->factory(__DIR__)->index()->removeCached('files-test', true);

* Git Reset

Method Signature:

See classes:

public function reset(ResetMode $mode, string $subject): void;

Equals Git Command:

git reset --$mode $subject

Example:

use \ArtARTs36\GitHandler\Factory\LocalGitFactory;

(new LocalGitFactory())->factory(__DIR__)->index()->reset(ResetMode::from(ResetMode::SOFT), 'subject-test');

* Git Reset Head

Method Signature:

See classes:

public function resetHead(ResetMode $mode): void;

Equals Git Command:

git reset --$mode HEAD~

Example:

use \ArtARTs36\GitHandler\Factory\LocalGitFactory;

(new LocalGitFactory())->factory(__DIR__)->index()->resetHead(ResetMode::from(ResetMode::SOFT));

* Rollback files state

Method Signature:

public function rollback(string|string[] $paths): void;

Equals Git Command:

git checkout HEAD $paths

Example:

use \ArtARTs36\GitHandler\Factory\LocalGitFactory;

(new LocalGitFactory())->factory(__DIR__)->index()->rollback('paths-test');

* Checkout to paths

Method Signature:

public function checkout(string $path, bool $merge = false): bool;

Equals Git Command:

git checkout $path

Example:

use \ArtARTs36\GitHandler\Factory\LocalGitFactory;

(new LocalGitFactory())->factory(__DIR__)->index()->checkout('/path/to/file', true);

* Cherry pick

Method Signature:

public function cherryPick(string $commitSha): void;

Equals Git Command:

git cherry-pick $commitSha

Example:

use \ArtARTs36\GitHandler\Factory\LocalGitFactory;

(new LocalGitFactory())->factory(__DIR__)->index()->cherryPick('commitSha-test');