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 statuswill tell us what files have been changed, but not what those changes actually were.

Thegit diffcommand is used to find out this information!

git diff

Thegit diffcommand can be used to see changes that have been made but haven't been committed, yet.

$ git diff

To seegit diffin 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 diffon the Terminal.

You should see the following:

The Terminal application showing the output of thegit diffcommand.

Wow, doesn't that look familiar! It's the same output that we say withgit log -p! Wanna know a secret?git log -pusesgit diffunder 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 ofgit 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 logwill look slightly different from mine because it includes this extra commit.

Git Diff Recap

To recap, thegit diffcommand 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

results matching ""

    No results matching ""