What is the difference between git diff HEAD vs. git diff --staged?

前端 未结 5 681
予麋鹿
予麋鹿 2021-01-29 19:18

What is the difference between git diff HEAD and git diff --staged? I tried both but both give the same output.

5条回答
  •  长发绾君心
    2021-01-29 19:59

    Suppose this output for git status:

    $ git status
    # On branch master
    # Changes to be committed:
    #   (use "git reset HEAD ..." to unstage)
    #
    #   new file:   y
    #
    # Changes not staged for commit:
    #   (use "git add ..." to update what will be committed)
    #   (use "git checkout -- ..." to discard changes in working directory)
    #
    #   modified:   x
    #
    

    As you see, there is one file modified but not staged for commit, and a new file added that is ready to be committed.

    git diff --staged will only show changes to files in the "staged" area.

    git diff HEAD will show all changes to tracked files. If you have all changes staged for commit, then both commands will output the same.

提交回复
热议问题