tags:

views:

33

answers:

1

As I understand it, a git commit object will always point exactly one tree object.

What I'm wondering is whether, in practice, this tree object is always guaranteed to be a git repository's top-level tree object, representing the entire state of my code at the point the commit object was created.

Is there any chance, in an actual git repository, that any commit object could point to a tree object lower down in the hierarchy?

+1  A: 

Well, commits DO always point to the entire tree/branch history as it was at the time of commit, but you're not limited to having just one history in your repository...

You can have a branch for ProjectA and a branch for ProjectB (with completely different histories and sets of files) and using the subtree merge strategy, you can merge ProjectB's changes into a subdirectory of ProjectA, keeping the history of ProjectB attached! Now, those commits from ProjectB's branch history will still be in the root of their branch, but the merge commit will map them into a subtree of ProjectA. You can even re-merge when there are more commits in ProjectB to get the updates in ProjectA.

Pretty confusing thing to do though, if you ask me... This Pro Git section suggests merging without keeping the history from the other branch, which seems a lot saner.

Justin W
Thanks. That subtree merge example helps me understand why commits are defined to simply point at a tree. Good to know that when a commit is made it always points to the entire tree.
Zubin