Skip to content

Latest commit

 

History

History
65 lines (47 loc) · 1.48 KB

File metadata and controls

65 lines (47 loc) · 1.48 KB

Working copy

Working copy is the folder associated to a git repository. In gitlib, you can access this object using the getWorkingCopy on a Repository object:

$repo = new Repository('/path/to/working-dir');
$wc = $repo->getWorkingCopy();

Checkout a revision

You can checkout any revision using checkout method. You can also pass a second argument, which will be passed as argument with -b:

// git checkout master
$wc->checkout('master');

// git checkout origin/master -b master
$wc->checkout('origin/master', 'master');

You can also pass a Reference or a Commit.

Merge a revision

You can merge any revision into the current branch using the merge method. A second argument can be used to pass extra options to the underlying git merge command:

// git merge origin/develop
$wc->merge('origin/develop');

// git merge --no-ff origin/develop
$wc->merge('origin/develop', ['--no-ff']);

You can also pass a Reference or a Commit. A RuntimeException is thrown if the merge fails (for instance because of a conflict).

Staged modifications

You can get a diff of modifications pending in staging area. To get the Diff object, call method getDiffStaged():

$diff = $wc->getDiffStaged();

Pending modifications

You can get pending modifications on tracked files by calling method getDiffPending():

$diff = $wc->getDiffPending();