126

I have changed several files in a git repository, but have not committed them yet.

I can get a list of the changes by just invoking git status. But how do I get a listing of the lines or the content that I have changed, in addition to the filenames?

I initially thought about using git diff, but it seems to be useful only for comparing already commited changes.

Usually I just do meld ., but on this case I'm connected to an external server via ssh.

Cœur
  • 37,241
  • 25
  • 195
  • 267
kikito
  • 51,734
  • 32
  • 149
  • 189

2 Answers2

192

git diff by default shows difference between your working directory and the index (staging area for the next commit).

If you have already added (staged) the changes to the staging area, git diff --staged does the job. Staging area is the data from which the next commit will be formed by git commit.

P. S. Good reading (IMO) for Git beginners:

rocarvaj
  • 546
  • 4
  • 19
Mischa Arefiev
  • 5,227
  • 4
  • 26
  • 34
  • Doesn't staged only apply to files not added yet? Thought you had to use the cached flag. – pbond Mar 06 '12 at 12:19
  • 4
    @peterbond `man git-diff` says `--staged is a synonym of --cached` – Mischa Arefiev Mar 06 '12 at 12:21
  • 2
    @peterbond Technically *staged* means *added to the staging area* which is not yet a commit. I have clarified that in the edit. – Mischa Arefiev Mar 06 '12 at 12:27
  • 1
    @Mischa The [documentation](http://linux.die.net/man/1/git-diff) says that the default behaviour for `git diff` is to compute the difference between the working directory and **the index**, not `HEAD` – Axel Mar 06 '12 at 13:00
  • It didn't occur to me to invoke git diff with no params. Thanks! – kikito Mar 06 '12 at 13:13
23

What i use for such cases is:

git diff HEAD *

This will show the changes since last commit. Although somehow it works quicker with

git diff .

or

git diff

To see the changes on previously git added files, use the staged flag:

git diff --staged
EliuX
  • 11,389
  • 6
  • 45
  • 40