Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
In this movie, we are going to apply what we just learned in the last movie about how to refer to commits, and we are going to use it to be able to look at the tree listings. Remember that I told you that a tree is a lot like a directory on your file system. If I am in Unix, and I want to get a list of the current files that are in the directory I am in right now, I use the ls command for list, ls -la is a set of options that formats it so that it runs in a nice vertical list with all of the file names, including file names that start with a dot over on the right side.
Now in Windows, you can do something similar with the dir command, but I want to stick with the ls of Unix for a second, because in Git, it's something very similar. To list out a tree, we use git ls-tree, listing the tree, and then what we pass in after that is a tree-ish. In fact, before we do it, let's take a look at the Help documentation, and notice right where it talks about how to use it, it says, get ls-tree, there is a whole bunch of options we can pass in and then after that it won't say tree-ish. So there it is. I am not making it up. That's the word for it, and it's a reference to the tree.
So let's try that, git ls-tree, and now we need a tree-ish. Well, one of the one is we can refer to the tree, is to use the HEAD that will point to the tip of the currently checked out branch, and it will return the list of files at that point. That's what's in the HEAD. Those are the files that are in the repository at that point, so that's what the repository thinks is the current set of files. If I were to check this out, brand new, from the repository, these are the files it would give me. Now those don't exactly match what I had in working directory because my working directory has some files that I have used gitignore on.
So you can play around and try out some different tree-ishes, so let's do git ls-tree master. That points to the exact same thing because we have the master branch checked out right now, so HEAD points to the tip of that, we are getting the exact same results. Let's take a look inside a directory there, we can pass in a file path after that, so git ls-tree master, and let's ask it for assets with the slash after it. So the contents of the assets directory, and it comes up and tells us the files that are inside that directory.
Now let's try going back one commit. I don't know if you remember, but one commit back is when we actually created this pdfs folder, that's when we added it. So unless you made other commits, in which case you may need to go back further, but one commit back will now show us that directory in its previous state. So in the commit before that, there was no pdfs folder, in the commit after it, now there is a pdfs folder. One more thing I want to show you, notice that each of these entries over here on the left, it tells you that everything is either a tree or a blob. A blob is a file. It can be any kind of file that's stored there.
It can be text file, an image, anything, they are all stored as a blob. If it's not a blob, then it's a tree and guess what a tree is? A tree is a directory. So we are inside a tree because we had a tree- ish that pointed us to a tree and then inside that tree are other trees. Well, that three has an object number, it goes with it. So we can grab the first part of that, copy it, and then we can say, well git ls-tree and pass in that SHA, that's a tree-ish that points to it and look what it gives us.
It gives us back the exact same thing that we had here, the only difference is that it doesn't prefix it with the assets directory because we have already told it it's the tree. This was telling us we were starting with master and then looking inside assets, so it listed assets for us. Here were starting at assets so it doesn't give us the prefix there. So try it out, play around little bit and get comfortable with it and make sure that you understand the things that we learned in the last movie about the different tree-ishes and the way that we can reference different trees this way.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 97496 Viewers
61 Video lessons · 84738 Viewers
71 Video lessons · 68918 Viewers
56 Video lessons · 101362 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.