# git diff

> The `git diff` command shows differences between file versions in the working directory and the staging area, or compares changes between commits.

## How do I see changes with git diff?

The command that shows line-by-line differences between the working directory and the staging area. With `--staged` it compares staged changes to the last commit, and it can also compare branches or commits.

- Topic: Git Commands - Main
- Type: command

## Example

Wrong:

```bash
git add .
git diff
```

Right:

```bash
git add .
git diff --staged
```

Plain `git diff` compares against the staging area, so staged changes only show with `--staged`.

## Common mistakes

- Running `git diff` after `git add` and seeing nothing, because staged changes need `--staged`.

## Interview questions

### How do I compare two branches with git diff?

Run `git diff main..feature`. To see only what the feature branch added since it split off, use `git diff main...feature`.

### How do I list only changed file names?

Run `git diff --name-only`. Add `--staged` or two refs to choose what to compare.

### What is the difference between git diff --staged and --cached?

None. They are two names for the same option.

## Related cards

- [git status](https://wonderium.dev/processes/git-status.md)
- [`git add <file>`](https://wonderium.dev/processes/git-add.md)
- [`git show <commit>`](https://wonderium.dev/processes/git-show.md)
- [Code Review](https://wonderium.dev/processes/code-review.md)
- [git log](https://wonderium.dev/processes/git-log.md)

---

- Level: [Processes](https://wonderium.dev/processes.md)
- HTML version: https://wonderium.dev/processes/git-diff
- Last updated: 2026-11-25
