A tree is a hierarchical collection of files and directories, not tied to any particular point in history. For example, if you create a file and then later delete the file (with no other intervening commits), you will end up with the same tree you started with.
A commit is a point in the history of your project. A commit specifies a tree, but also contains other information such as author/committer and time, a commit message (in which the author describes what changed), and most importantly zero or more parents, which are the previous state of the repository. (Your very first commit has zero parents. Most commits after that have one parent during linear development, and more than one if you merge.)
You can get a sense of how this works with the git cat-file -p
command, which prints the contents of a particular hash, regardless of the type. For example, to look at the HEAD commit, you can run:
$ git cat-file -p HEAD
tree 81ca1cb660ea79131336944df28b13b711d93557
parent 92b6b8fe9956866ace5397e060e7cc8ee1c76233
parent 7ea2575ed96d150ee19f70edea4bd42c7c2f0b83
author Mislav MarohniÄ <mislav.marohnic@gmail.com> 1436468108 -0700
committer Mislav MarohniÄ <mislav.marohnic@gmail.com> 1436468108 -0700
Merge pull request #951 from github/global-args
Avoid depending on a hardcoded list of git global flags
To see the tree inside that commit, you can cat-file -p
it's tree:
$ git cat-file -p 81ca1cb660ea79131336944df28b13b711d93557
100644 blob 730f77a3be502cfe6769c1305c0b59c22274caf5 .gitignore
100644 blob bcbd000f6b9ad5b0510f804ac4a3b19306b39c03 .travis.yml
100644 blob da71aa1fa3c3ae47b2fe5e6245ce2eea1586e278 CONTRIBUTING.md
...
Similarly, if you look at the parents, you will see those are commits as well. A shorthand for the tree inside a commit such as rev
is rev^{tree}
. So the previous command could have been written git cat-file -p HEAD^{tree}
. Note that rev^
stands for the parent of rev
. When there are multiple parents, rev^1
, rev^2
, etc. More information is available in the git rev-parse man page.
commit has
mean in the beginning of your 3rd paragraph? – Zen Nov 01 '14 at 04:51