Loading

Quipoin Menu

Learn • Practice • Grow

git / Viewing Changes
tutorial

Viewing Changes

Before you stage or commit changes, you might want to see exactly what has changed in your files. Git provides git diff to show differences between versions.

git diff – What’s Changed?

When you modify files, git diff shows the lines that have been added (green, with +) and removed (red, with -).

Let’s create a new file and see it in action:
echo "Line 1" > file.txt
git add file.txt
git commit -m "Add file.txt with line 1"
echo "Line 2" >> file.txt
Now run:
git diff
You’ll see a difference: +Line 2.

Diff Between Staged and Last Commit

If you stage the change (git add file.txt) and then run git diff, you’ll see nothing because git diff compares working directory with staging area. To compare staged changes with the last commit, use:
git diff --staged
(or git diff --cached)

Comparing Commits

You can compare any two commits using their hashes. First, find the hashes with git log --oneline. Then:
git diff hash1 hash2

Using a Diff Tool

For more visual diff, you can configure a GUI diff tool like meld or vscode. But the command‑line diff is enough for most purposes.

Practical Example: See What You’re About to Commit

A common workflow:
  1. Make changes.
  2. Run git diff to review them.
  3. Stage with git add.
  4. Run git diff --staged to double‑check what will be committed.
  5. Commit with a message.


Two Minute Drill
  • git diff shows unstaged changes (working vs staging).
  • git diff --staged shows staged changes vs last commit.
  • You can compare two commits with git diff commit1 commit2.
  • Use diff to review changes before staging or committing.

Need more clarification?

Drop us an email at career@quipoinfotech.com