git cat-file -p HASH. It is a good idea to get familiar with some git internals, although if you have already used git, many things are quite straightforward.If you find the glip API to be lacking in some respect—extend it! :-)
The glip homepage is at <http://fimml.at/glip>.
b1950c3ed1a8121abec98075548da4b03d82a8e3, andglip provides sha1_hex() and sha1_bin() to convert between the two representations.
$repo = new Git('test.git');
All objects in the repository are mapped to instances of GitObject subclass, i.e. GitBlob, GitTree or GitCommit. If you know the SHA-1 hash of a git object, you can use Git::getObject to create a corresponding GitObject instance.
$some_object = $repo->getObject(sha1_bin('b1950c3ed1a8121abec98075548da4b03d82a8e3'));
In most cases, you will not know the SHA-1 hash of the object you want yet. Instead, you might want to look up the tip of a branch with Git::getTip:
$master_name = $repo->getTip('master');
$master = $repo->getObject($master_name);
GitObjects hold all related data in public attributes. For example, GitCommit::$summary contains the commit summary of a particular commit. Utility functions are provided to make it easier to perform common functions.
Creating a new object can be done in two ways:
$object = clone $similar_object; /* OR */ $object = new GitBlob($repo); /* or GitTree or GitCommit */
clone when modifying an object you received from Git::getObject() or another glip function calling it. Objects might be cached across Git::getObject() calls in future.
$object = new GitBlob($repo); $object->data = "Hello World\n"; $object->rehash();
You can now use GitObject::getName() to get the object's SHA-1 sum and possibly reference it in other GitObjects.
The object has not written to disk yet. To do so, use GitObject::write():
$object->write();
Et voilĂ ! You just wrote a new object to a git repository from PHP. If you actually execute the example code listed here, the result will be similar to that of echo Hello World | git hash-object -w --stdin.
The same procedure applies to GitTree and GitCommit as well, just that they have different attributes to modify.
1.5.9