git diff command
The git diff command compares differences between files, i.e., it compares the differences between the staging area and the working directory.
The git diff command shows the difference between files that have been written to the staging area and files that have been modified but not yet written to the staging area.
git diff has two main application scenarios.
- Changes not yet staged:git diff
- View staged changes:git diff --cached
- View all staged and unstaged changes:git diff HEAD
- Show summary instead of entire diff:git diff --stat
Show differences between the staging area and the working directory:
$ git diff [file]
Show the differences between the staging area and the last commit:
$ git diff --cached [file] 或 $ git diff --staged [file]
Show differences between two commits:
$ git diff [first-branch]...[second-branch]
Enter the following content in the hello.php file:
<?php echo 'Example:www.example.com'; ?>
Use git status to view the status:
A README
AM hello.php
$ git diff
diff --git a/hello.php b/hello.php
index e69de29..69b5711 100644
--- a/hello.php
+++ b/hello.php
@@ -0,0 +1,3 @@
+<?php
+echo 'Example: www.example.com';
+?>
git status shows changes since your last commit or changes staged for commit, while git diff shows line by line what these changes actually are.
Next, let's take a look.git diff --cachedExecution effect:
$ git status -s
A README
A hello.php
$ git diff --cached
diff --git a/README b/README
new file mode 100644
index 0000000..8f87495
--- /dev/null
+++ b/README
@@ -0,0 +1 @@
+# Example Git Test
diff --git a/hello.php b/hello.php
new file mode 100644
index 0000000..69b5711
--- /dev/null
+++ b/hello.php
@@ -0,0 +1,3 @@
+<?php
+echo 'Example: www.example.com';
+?>
other extensions