Reputation: 8463
I keep noticing this whenever I'm trying to add links to github files. You can add a link using blob
:
https://github.com/facebook/pop/blob/master/Podfile
And the same doc comes up if you change blob to tree
:
https://github.com/facebook/pop/tree/master/Podfile
What is the difference? Whenever I want to add a link for posterity in a doc, which one should I prefer?
Upvotes: 47
Views: 17545
Reputation: 372
I found this article helpful. This explains the git objects in detail.
Essentially, a blob is just a bunch of bytes that could be anything, like a text file, image, actual source code etc.
A tree is like a directory, it points to:
tree
/ | \
blob tree blob
|
blob
Hopefully the above example clarifies the difference.
In your example, Podfile
is a file containing source code. Hence, it is a blob
object. However, git is smart and realizes this fact. Hence, when you click the link, it changes the tree
in the link to blob
. You can try and test this yourself by clicking the below tree
link:
https://github.com/facebook/pop/tree/master/Podfile
Similary, if you go to a directory on a git repository it is a tree
object. Again, if you change the tree
to blob
git is smart and realizes that it is actually a directory and not a file and changes the blob
in the link to tree
. Again, you can try and test this yourself:
https://github.com/facebook/pop/blob/master/pop-tests
In terms of which link to prefer when you want to add to a document, it depends on what does the link point to. Essentially, there are 4 types of git objects:
Hope that answers your question. I still recommend going through the article to get a thorough understanding of git objects.
Upvotes: 14
Reputation: 2122
GitHub's website currently seems to be:
blob
for files, and tree
for directories, in URLs;tree
to contain blob
instead; andblob
to URLs containing tree
instead.It's possible that GitHub's website, at the time you asked the question, was only rewriting file URLs between tree
and blob
, instead of properly redirecting them. (Rewriting and redirecting URLs are activities of web servers.) If so, then the change wouldn't appear in your browser's address bar. But maybe you didn't mean that.
Upvotes: 13
Reputation: 24617
A blob is a representation of a file, and file diffs are separated into contiguous modified chunks named hunks
. Hunks are @@
delimited lines in the git diff
output format.
A tree is a representation of a directory. There are different types of trees:
working tree
The tree of actual checked out files. The working tree normally contains the contents of the HEAD commit tree, plus any local changes that you have made but not yet committed.
index
A collection of files with stat information, whose contents are stored as objects. The index is a stored version of your working tree. Truth be told, it can also contain a second, and even a third version of a working tree, which are used when merging.
tree-ish
A ref pointing to either a commit object, a tree object, or a tag object pointing to a tag or commit or tree object.
There are four types of objects in Git’s internal storage. Commit objects, annotated tag objects, blobs and tree objects.
References
Upvotes: 4