See the changes of a file before staging and before commit
Description: Change a line in a tracked file. Show the change before staging, then stage the file and show the staged change.
Hint:
- Plain
git diffshows unstaged changes, and--stagedshows staged changes.
Solution
Terminal output
$ printf "Tea\nMilk\n" > drinks.txt
$ git diff
diff –git a/drinks.txt b/drinks.txt
index 345af57..4227ee2 100644
— a/drinks.txt
+++ b/drinks.txt
@@ -1,2 +1,2 @@
Tea
-Coffee
+Milk
$ git add drinks.txt
$ git diff
$ git diff –staged
diff –git a/drinks.txt b/drinks.txt
index 345af57..4227ee2 100644
— a/drinks.txt
+++ b/drinks.txt
@@ -1,2 +1,2 @@
Tea
-Coffee
+Milk
How it works
- Lines with
-are removed and lines with+are added. - After
git add, plaingit diffis empty, because there is no unstaged change.
Read Git Diff.
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |