Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
In the last movie we saw how we could use git diff to get details about the changes that were in our working directory. In this movie we are going to see how we can do the same thing with our staging index. Now the first thing, of course, we need to do is put something in our staging index, so let's do that with first_file.txt. We know how to do that with git add first_file.txt, now it's in our staging index. Git status will show us, first_file, those changes are now staged. The changes to third_file.txt are just in our working directory.
If we were to do a git diff now, it would just report the changes that are in our working directory. So when I told you earlier that it was comparing your working directory with the repository, that's not quite true, it's actually comparing it against the staging index and the repository. So it's things that are unique, things that are different about the working directory only. So what about those changes for first_file, how do we see those? Well, we do the same thing using git diff, but now we pass in another option, which is staged, git diff --staged.
It's the option to diff that tells it to look at what's in the staging index and compare that against the repository. So now you can see we're only seeing changes that we made to first_file.txt. So git diff by itself will return the changes that are in the working directory. I also just want to note for you that git diff --staged in versions before 1.6 of Git, it was actually called cached. But that wasn't as clear to people and so they standardized on calling it the staging index, and it became called staged.
Now, you should be working with version 1.7 of Git or later, so it should be staged for you, but cached also still works, it does the same thing, it returns the exact same information. But we are going to stick with using staged. So now just like before, of course, if we git add our third_file, now git status, you can see that both of those files are now in the staging index and git diff returns no changes, git diff --staged will show us both sets of changes.
So the last thing we want to do is let's go ahead and just save our changes. So we've got these to be committed already, these are in our staging index, so we're just going to do git commit, and let's just give it a simple message, we'll say Minor text edits. So there it is committed, now if we do git status, our working directory is clean again.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 101355 Viewers
61 Video lessons · 88117 Viewers
71 Video lessons · 71955 Viewers
56 Video lessons · 103782 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.