391

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

7 Answers 7

646

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
  • 4
    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) Commented Jun 16, 2018 at 23:55
  • 3
    --staged and --cached are synonyms
    – eugenevd
    Commented Aug 20, 2020 at 14:10
  • 1
    For completeness I would include git diff dev..origin/dev
    – doveryai
    Commented 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
    Commented 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
    Commented Oct 23, 2022 at 12:57
65

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.

2

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

Output:
enter image description here

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

TL;DR

  • Reference image ( PS screen shot )

    • Image Key

      Shape Color Command / Description
      Red git status
      Yellow git status -b -s
      Purple PowerShell modules posh-git and posh-with functionality
  • Troubleshooting fatal: ambiguous argument 'master'

    • git pull; git branch -a
      • Pulls down latest copy of repo, lists all branches in repo
        • Issue likely caused by 2 branches ( local and remote ) both named master, but neither is specified in git diff command
  • Show uncommitted changes : git status

    • Example command output shown in Reference Image
      • git status : RED rectangle
      • git status -b -s : YELLOW rectangle
        • -b shows working branch and target branch info
        • -s is for short output
      • Additional git status documentation
  • PS, aka PowerShell

    • posh-git and posh-with modules : PURPLE rectangle / CYAN branch data
      # PowerShell Module Imports
      Import-Module posh-git   # install before usable | Install-Module posh-git -Scope CurrentUser
      Import-Module posh-with  # install before usable | Install-Module posh-with -Scope CurrentUser
      
      • NOTE: Modules can be installed without admin privileges (-Scope currentUser)

Reference Image Key


... Apologies in advance if this is too much detail...

1. The Error message

  • ambiguous argument 'master': unknown revision or path not in the working tree
    • Pretty sure this means that the local repo doesn't know about the branch master
      • Try git pull; git branch -a
      • This will pull the latest copy of the remote repo and display all local and remote branches on the terminal
        • If the branch was created on the git website or gui, the local repo may not know about the newly created branch

2. Showing uncommitted changes in Git

There are any number of ways to check uncommitted changes, but I will focus on doing so in PowerShell from the cmd

  • git status
    • This command in PS (or really any shell) will show many things such as:
      • changed but uncommitted files
      • files that will be committed on next commit
      • untracked files on local machine/branch
    • the additional flags/options may be added on to the command, such as -b to show branch information, and -s to shorten the output

3. PowerShell

I use PowerShell at work as our team has a decent amount of PS code, but this process should be applicable to most shells (with some instruction tweaking)

Two very useful Modules are available for PowerShell: posh-git and posh-with

# PowerShell Module Imports
Import-Module posh-git   # install before usable | Install-Module posh-git -Scope CurrentUser
Import-Module posh-with  # install before usable | Install-Module posh-with -Scope CurrentUser
  • These modules may be installed for only the currentUser (no admin rights!)
  • Once installed, the modules may be added to Microsoft.PowerShell_profile.ps1
    • If added to the above file (PowerShell User Profile), the modules are imported at the beginning of every PS session

[ORIGINAL COMMENT]

  • git status
    • shows file changes, files to be committed, untracked files, etc.
  • error message
    • appears to be caused by local and remote branches with same name, but not specifying which branch
  • powershell
    • if using powershell, there are 2 modules that can be installed for currentUser and make working with git from the command line much easier
      # PowerShell Module Imports
      Import-Module posh-git   # install before usable | Install-Module posh-git -Scope CurrentUser
      Import-Module posh-with  # install before usable | Install-Module posh-with -Scope CurrentUser
      

Reference image (powershell screen shot)

1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Feb 28 at 19:24
-1

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 you have read our privacy policy.

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