Search code examples
gitgit-diff

What is 'git diff' short-hand for, if anything?


If I modify a file and do git diff I see the diff in the terminal.

If I then stage the modified file and do git diff again, there is no diff. If I instead do git diff HEAD i see the diff in the terminal, like before staging it.

So what is git diff short-hand for? I thought it was the same as git diff HEAD but obviously not.


Solution

  • git diff compares the working tree (the files on disk) to the index (the staged modifications).

    AFAIK, it isn't the shorthand of any other compbination of arguments.


    The examples section of the documentation explains pretty well the subtleties around the "compare the latest changes" commands :

    Various ways to check your working tree

    $ git diff            (1)
    $ git diff --cached   (2)
    $ git diff HEAD       (3)
    
    1. Changes in the working tree not yet staged for the next commit.
    2. Changes between the index and your last commit; what you would be committing if you run git commit without -a option.
    3. Changes in the working tree since your last commit; what you would be committing if you run git commit -a

    In that list : (2) is a shorthand for git diff --cached HEAD, but I don't know of any other way to write (1) or (3).