|
| 1 | +### Tree Object ### |
| 2 | + |
| 3 | +The ever-versatile linkgit:git-show[1] command can also be used to |
| 4 | +examine tree objects, but linkgit:git-ls-tree[1] will give you more |
| 5 | +details: |
| 6 | + |
| 7 | + $ git ls-tree fb3a8bdd0ce |
| 8 | + 100644 blob 63c918c667fa005ff12ad89437f2fdc80926e21c .gitignore |
| 9 | + 100644 blob 5529b198e8d14decbe4ad99db3f7fb632de0439d .mailmap |
| 10 | + 100644 blob 6ff87c4664981e4397625791c8ea3bbb5f2279a3 COPYING |
| 11 | + 040000 tree 2fb783e477100ce076f6bf57e4a6f026013dc745 Documentation |
| 12 | + 100755 blob 3c0032cec592a765692234f1cba47dfdcc3a9200 GIT-VERSION-GEN |
| 13 | + 100644 blob 289b046a443c0647624607d471289b2c7dcd470b INSTALL |
| 14 | + 100644 blob 4eb463797adc693dc168b926b6932ff53f17d0b1 Makefile |
| 15 | + 100644 blob 548142c327a6790ff8821d67c2ee1eff7a656b52 README |
| 16 | + ... |
| 17 | + |
| 18 | +As you can see, a tree object contains a list of entries, each with a |
| 19 | +mode, object type, SHA1 name, and name, sorted by name. It represents |
| 20 | +the contents of a single directory tree. |
| 21 | + |
| 22 | +The object type may be a blob, representing the contents of a file, or |
| 23 | +another tree, representing the contents of a subdirectory. Since trees |
| 24 | +and blobs, like all other objects, are named by the SHA1 hash of their |
| 25 | +contents, two trees have the same SHA1 name if and only if their |
| 26 | +contents (including, recursively, the contents of all subdirectories) |
| 27 | +are identical. This allows git to quickly determine the differences |
| 28 | +between two related tree objects, since it can ignore any entries with |
| 29 | +identical object names. |
| 30 | + |
| 31 | +(Note: in the presence of submodules, trees may also have commits as |
| 32 | +entries. See <<submodules>> for documentation.) |
| 33 | + |
| 34 | +Note that the files all have mode 644 or 755: git actually only pays |
| 35 | +attention to the executable bit. |
| 36 | + |
| 37 | +### Blob Object ### |
| 38 | + |
| 39 | +You can use linkgit:git-show[1] to examine the contents of a blob; take, |
| 40 | +for example, the blob in the entry for "COPYING" from the tree above: |
| 41 | + |
| 42 | + $ git show 6ff87c4664 |
| 43 | + |
| 44 | + Note that the only valid version of the GPL as far as this project |
| 45 | + is concerned is _this_ particular version of the license (ie v2, not |
| 46 | + v2.2 or v3.x or whatever), unless explicitly otherwise stated. |
| 47 | + ... |
| 48 | + |
| 49 | +A "blob" object is nothing but a binary blob of data. It doesn't refer |
| 50 | +to anything else or have attributes of any kind. |
| 51 | + |
| 52 | +Since the blob is entirely defined by its data, if two files in a |
| 53 | +directory tree (or in multiple different versions of the repository) |
| 54 | +have the same contents, they will share the same blob object. The object |
| 55 | +is totally independent of its location in the directory tree, and |
| 56 | +renaming a file does not change the object that file is associated with. |
| 57 | + |
| 58 | +Note that any tree or blob object can be examined using |
| 59 | +linkgit:git-show[1] with the <revision>:<path> syntax. This can |
| 60 | +sometimes be useful for browsing the contents of a tree that is not |
| 61 | +currently checked out. |
0 commit comments