StackTips
 3 minutes

Git Diff – Inspecting and Comparing Changes in Git

By Nilanchala @nilan, On Sep 17, 2023 Git 2.38K Views

The git diff command helps you see, compare, and understand changes in your project before you can push your code to the server. It can be used to look at current changes in your working copy, past changes in commits, or even to compare branches.

In this short article, we’ll talk about the most important use cases you need in your daily work.

Look for what changed since I last committed?

Running the plain git diff command without any parameters can be pretty helpful: it will show you all of your local changes since you last committed.

$ git diff

When you want to do a git diff but do not care about the full diff and just want to know which files changed

$ git diff --name-only

To include some brief information about changed lines

$ git diff --stat

View changes in staging area?

By adding the --staged option, Git will show which local changes you have already added to Staging Area, via “git add”:

# Staged changes in a certain file…

$ git diff --staged index.html

# Staged changes in all local files…

$ git diff --staged
nilan avtar

Nilanchala

I'm a blogger, educator and a full stack developer. Mainly focused on Java, Spring and Micro-service architecture. I love to learn, code, make and break things.