billfeller.github.io icon indicating copy to clipboard operation
billfeller.github.io copied to clipboard

git diff --staged与git diff HEAD的区别

Open billfeller opened this issue 6 years ago • 0 comments

首先需要知道Git 项目包含三个工作区域的概念:工作目录、暂存区域以及Git 仓库。

  1. 已修改(modified):修改了文件,但还没保存到数据库中。
  2. 已暂存(staged):对一个已修改文件的当前版本做了标记,使之包含在下次提交的快照中。
  3. 已提交(committed):数据已经安全的保存在本地数据库中。

image

  1. git diff --staged表示暂存区域与Git仓库的区别;
  2. git diff HEAD表示工作区域Git仓库的区别;

通过 git status 可以查看到区别:

$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   xxxxxxx

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   xxxxxxx

参考:https://stackoverflow.com/questions/16562121/git-diff-head-vs-staged

billfeller avatar Mar 20 '18 01:03 billfeller