356

How do I show uncommitted changes in Git?

I STFW'ed, and these commands are not working:

teyan@TEYAN-THINK MINGW64 /d/nano/repos/PSTools/psservice (teyan/psservice)
$ git status
On branch teyan/psservice
Your branch is up-to-date with 'origin/teyan/psservice'.
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   psservice.c
        modified:   psservice.vcxproj.filters


teyan@TEYAN-THINK MINGW64 /d/nano/repos/PSTools/psservice (teyan/psservice)
$ git diff

teyan@TEYAN-THINK MINGW64 /d/nano/repos/PSTools/psservice (teyan/psservice)
$ git diff master
fatal: ambiguous argument 'master': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
0

6 Answers 6

610

How to show uncommitted changes in Git

The command you are looking for is git diff.

git diff - Show changes between commits, commit and working tree, etc


Here are some of the options it expose which you can use

git diff (no parameters)
Print out differences between your working directory and the index.

git diff --cached:
Print out differences between the index and HEAD (current commit).

git diff HEAD:
Print out differences between your working directory and the HEAD.

git diff --name-only
Show only names of changed files.

git diff --name-status
Show only names and status of changed files.

git diff --color-words
Word by word diff instead of line by line.

Here is a sample of the output for git diff --color-words:

enter image description here

6
  • 3
    When you see the colon prompt at the end, it means git has shown the first page - press enter to step through the other changes (like you can with cat file | more) Jun 16, 2018 at 23:55
  • 3
    --staged and --cached are synonyms
    – eugenevd
    Aug 20, 2020 at 14:10
  • 1
    For completeness I would include git diff dev..origin/dev
    – doveryai
    Oct 12, 2020 at 20:17
  • It's important to note, that you need to type HEAD all in capitals. I tried to use Head and it failed.
    – winklerrr
    Dec 23, 2020 at 11:58
  • 1
    @CodeWizard what style of documentation did you use? I find it very effective and would love to learn how to replicate.
    – albvar
    Oct 23, 2022 at 12:57
61

You have already staged the changes (presumably by running git add), so in order to get their diff, you need to run:

git diff --cached

(A plain git diff will only show unstaged changes.)

For example: Example git diff cached use

0
10

For me, the only thing which worked is

git diff HEAD

including the staged files, git diff --cached only shows staged files.

1

I had a situation of git status showing changes, but git diff printing nothing, although there were changes in several lines. However:

$ git diff data.txt > myfile
$ cat myfile
<prints diff>

Git 2.20.1 on raspbian. Other commands like git checkout, git pull are printing to stdout without problems.

1

Certainly not the right way to show uncommitted files, but it works:
git switch <current-branch>

Output:
enter image description here

-2

enter image description here

You can goto Visual Studio Control. Click on Source Control on the left hand side. it will show all uncommitted changes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.