【Git Snippets】Git diff

182 阅读1分钟

The Git snippet collection contains a variety of short tips and tricks for all currently maintained versions of git. It includes most commonly-used commands and covers various use-cases in the form of simplified documentation, complete with multiple examples.

Short code snippets for all your development needs.

View differences in changes

Displays differences between staged or unstaged changes and the last commit.

  • Use git diff to view differences between your unstaged changes and the last commit.
  • You can use the --staged option to view differences between your staged changes and the last commit instead.
$ git diff [--staged]

Example

$ git diff
# Displays the differences between unstaged changes and the last commit

$ git diff --staged
# Displays the differences between staged changes and the last commit
  • Distinction
    • unstaged changes: before execute git add . , like this picture:
    • staged changes: after execute git add . , but before git commit -m !

🔥Here shows the operation:

① before git add

git diff

② after git add & before git commit

git diff --staged

③ show the diff after git commit

🌊Wish you can benefit from this article. 🍺And welcome to leave your thoughts in the comments section that we can discuss and share ideas with each other.