Git Diff

As mentioned in the last chapter, the git status command gives us a great overview of the files that have changed, but it does not show us what the changes actually are.

You can check the actual changes that were made with the git diff command. If we were to run the command in our repository, we would see the following output:

diff --git a/ b/
index 9366068..2b14655 100644
--- a/
+++ b/
@@ -1 +1,2 @@
 # Demo Project
+Git is awesome

As we only changed the file, Git is showing us the following:

  • diff --git a/ b/ here git indicates that it shows the changes made to the file since the last commit compared to the current version of the file.
  • @@ -1 +1,2 @@: here git indicates that 1 new line was added
  • +Git is awesome: here, the important part is the +, which indicates that this is a new line that was added. In case that we remove a line, you would see a - sign instead.

In our case, as we only added 1 new line to the file, Git indicates that only 1 file was changed and that only 1 new line was added.

Next, let's go ahead and stage that change and commit it with the comments that we've learned from the previous chapters!

  • Stage the changed file:
git add
  • Then again run git status to check the current status:
git status

The output would look like this, indicating that there is 1 modified file:

On branch main
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
  • Commit the changes:
git commit -m "Update"

Finally, if you run git status again you will see that there are no changes to be committed.

I always run git status and git diff before making any commits, just so that I'm sure what has changed.

In some cases, you would like to see a list of the previous commits. We will learn how to do that in the next chapter.

Back to DevDojo