How to show uncommitted changes in Git and some Git diffs in detail

前端 未结 4 1803
天涯浪人
天涯浪人 2020-12-22 14:50

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 (         


        
相关标签:
4条回答
  • 2020-12-22 15:28

    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 讨论(0)
  • 2020-12-22 15:44

    For me, the only thing which worked is

    git diff HEAD
    

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

    0 讨论(0)
  • 2020-12-22 15:44

    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.

    0 讨论(0)
  • 2020-12-22 15:48

    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:


    0 讨论(0)
提交回复
热议问题