View diff of staged changes in git

26,441

One more minute of Googling found the answer of course, answering my own question:

git diff --cached
Share:
26,441
Daniel DiPaolo
Author by

Daniel DiPaolo

Just some dude.

Updated on March 10, 2020

Comments

  • Daniel DiPaolo
    Daniel DiPaolo about 4 years

    Possible Duplicate:
    How do I show the changes which have been staged?

    Is there a simple way to view the diff of only the staged changes I have pending in git? I've staged several files but want to take one last look at what I'm committing before I push the button. I have several other unstaged changes that I want to go in a separate commit, so unstaging, doing git diff, and then paging through to the file I want isn't all that desirable an option.

    Example:

    $ git status
    # On branch master
    # Changes to be committed:
    #   (use "git reset HEAD <file>..." to unstage)
    #
    #       modified:   foo.java
    #
    # Changed but not updated:
    #   (use "git add/rm <file>..." to update what will be committed)
    #   (use "git checkout -- <file>..." to discard changes in working directory)
    #
    #       modified:   bar.java
    #       modified:   baz.java
    #       modified:   qux.java
    

    I really just want to see what I changed in foo.java without having to unstage.

  • user1284631
    user1284631 over 11 years
    git diff --staged is a synonim and is more mnemonic for this case