'git diff' doesn't give any output

前端 未结 9 2145
迷失自我
迷失自我 2020-12-08 09:11

If I run git diff I would expect to see a list of changes of my working directory relative to whatever had been committed before (or a list of the working direc

相关标签:
9条回答
  • 2020-12-08 10:01

    I had a LESS=-R environment variable set. It made git diff show a blank screen.

    The solution for me:

    unset LESS
    
    0 讨论(0)
  • 2020-12-08 10:04

    I have seen situations where there really should be output from git diff, but there isn't; adding --no-pager in between git and diff does work:

    git --no-pager diff
    

    ...so does explicitly setting the pager to be less with

    git config --global core.pager 'less'
    

    Even though less is supposed to be the default pager.

    This was in Ubuntu 12.04 LTS (Precise Pangolin).

    I found the information about pager settings in the Git documentation.

    0 讨论(0)
  • 2020-12-08 10:04

    GIT DIFF DOESN'T WORK AFTER STASH

    Someone may run into this after attempting to apply stashed changes like I did.

    • Stash changes
    • Move to different branch and do some work
    • return to work-in-progress branch, update (git pull) then git stash apply (possibly with merge conflict)
    • git diff no longer works...

    At this point simply stash your changes again (git stash), do git pull to ensure everything is up to date (because I'm paranoid about it), double check that all files are up to date in working directory (possibly run rsync if dealing with remote/local), then attempt to git stash apply again and it should work!

    In answer to the original question, git diff isn't showing anything because you have a brand new directory, with a newly added file, but there are zero changes in the file for git diff to show. git status is showing that you added a new file, but git diff is for showing changes within files. If you made changes to the file, committed it, then made additional changes to it and ran git diff it would then show you the changes to the file.

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