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 edit files and commit those to the repository. In this movie I'd like us to take a look at how we can see what changes have been made before we make a decision about whether to commit those to the repository. Before we begin that, let's make some edits. So let's open up our first_file.txt, and this is the first file added to my project, and I'm going to say space, it comes before all other files. Hit Return. I'll save the whole thing, close it up. Now, we know what's going to happen if we do git status, it's going to tell us that the file was modified, right? What we want to do now though is find out what were those modifications.
This is very useful, especially if we've been working for a couple of hours, we've been making lots of changes to lots of files in our project, and maybe we were a little surprised even to see that the file popped up here in the modified list, we don't remember making a change to that file. How can we refresh our memory? What changed about this file? In the UNIX world it's very common to use a program called diff, D-I-F-F, in order to compare two files. And so Git uses that as the term that it uses to show us a diff between the old version and the new version. And we do that just with git diff.
So git diff will compare the two, that's comparing what's in the repository, the version that HEAD is pointing at, versus what's in our working directory. So the version in the repository is the one with the minuses, the one that has the pluses is going to be what's in the new version. So the old version was, this is the first line that I added to my project. The new version replaced that line with this line, this is the first file added to my project, and added two more new lines, it comes before all other files. Of course, what I changed here was just this little bit of text, it doesn't tell us that, it tells us on a line by line basis what is different.
It also notes that there's no new line at the end of this file, which means that we don't have a line return after the period. We do have a line return after this one here. So you can kind of ignore this line, don't worry too much about it. Main thing that you want to see is that this line has been removed, this line has been added, as well as these two lines have been added, that's what it's telling us. Now, if we'd had a long document, let's say it was 300 lines long, it would just highlight just the little bit that had changed. It wouldn't show us the whole document, it would just say, oh, you know what, this is the bit that's changed, and this little bit right here would actually tell us what line numbers we were looking at. That's a subtle but important point.
In most text editors there is a way to view line numbers. For example, in TextMate, under the View Menu, in the Gutter, I can tell it to show me line numbers. Then it will show the line numbers out here, and that will help you locate these changes relative to what's being told to you in the diff file. Now, if we'd had changes to more than one file, let's take a look here, let's open up a third file, and we'll just say, This is the last file in the project right now. Save that, come back over here, and let's take a look at git diff again.
And you'll see that it tells me, here is the changes in first file, here's the changes in third file, it lists them one after the other. If I wanted just one of those, of course, git diff with first_file.txt would just report the changes to that single file. So we can see all of the changes that have been made, that's all of the changes listed here under modified, or we can go file by file and take a peek at each one of them. Now, when we do this we're looking at the difference between the repository version and our working directory.
In the next movie let's look at how we see the changes that are in our staging directory.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 98559 Viewers
61 Video lessons · 85845 Viewers
71 Video lessons · 69745 Viewers
56 Video lessons · 102050 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.