Git Diff
Why Do We Need This
You might be like me where I start work on the next feature to my project at night, but then go to bed before I actually finish. Which means that, when I start working the next day, there are uncommitted changes. This is fine because I haven't finished the new feature, but I can't remember exactly what I've done since my last commit.git status
will tell us what files have been changed, but not what those changes actually were.
Thegit diff
command is used to find out this information!
git diff
Thegit diff
command can be used to see changes that have been made but haven't been committed, yet.
$ git diff
To seegit diff
in action, we need some uncommitted changes! Inindex.html
, let's reword the heading. Change the heading from "Expedition" to "Adventure". Save the file and rungit diff
on the Terminal.
You should see the following:
The Terminal application showing the output of thegit diff
command.
Wow, doesn't that look familiar! It's the same output that we say withgit log -p
! Wanna know a secret?git log -p
usesgit diff
under the hood. So you've actually already learned how to read the output ofgit diff
!
If you don't remember what the different sections are, check out the Annotated "git log -p" Output from the previous lesson.
💡 These Changes Were Not Committed 💡
The changes in this section were used to demo the output of
git diff
. They were not committed to the repository. If you'd like, you can definitely commit the changes to the repository, just know that yourgit log
will look slightly different from mine because it includes this extra commit.
Git Diff Recap
To recap, thegit diff
command is used to see changes that have been made but haven't been committed, yet:
$ git diff
This command displays:
- the files that have been modified
- the location of the lines that have been added/removed
- the actual changes that have been made
Further Research
- git diff from the Git Docs