DIY_GIT_in_Python/how_to/Change_05.md

823 B
Raw Blame History

  • cat-file: Print hashed objects

This command is the “opposite” of hash-object: it can print an object by its OID. Its implementation just reads the file at “.ugit/objects/{OID}”.

The names hash-object and cat-file arent the clearest of names, but they are the names that Git uses so well stick to them for consistency.

We can now try the full cycle:

$ cd /tmp/new
$ ugit init
Initialized empty ugit repository in /tmp/new/.ugit
$ echo some file > bla
$ ugit hash-object bla
0e08b5e8c10abc3e455b75286ba4a1fbd56e18a5
$ ugit cat-file 0e08b5e8c10abc3e455b75286ba4a1fbd56e18a5
some file

Note that the name of the file (bla) wasnt preserved as part of this process, because, again, the object database is just about storing bytes for later retrieval and it doesnt care which filename the bytes came from.