Introduction
🧑💻 New to Git or LabEx? We recommend starting with the Quick Start with Git course.
Git is a popular version control system that allows developers to track changes made to their codebase. One of the essential features of Git is the ability to view differences between changes made to a file. This feature is useful when you want to see what changes you have made to a file or compare changes between different versions of a file.
View Differences in Changes
As a developer, you may want to view the differences between your staged or unstaged changes and the last commit. This is useful when you want to review your changes before committing them or when you want to see what changes you have made since the last commit.
To demonstrate how to view differences in changes, we will use the git-playground repository. Suppose you have made some changes to the README.md file and want to view the differences between your changes and the last commit.
- Open your terminal and navigate to the
git-playgrounddirectory:
cd git-playground
- Use the
git diffcommand to view the differences between your unstaged changes and the last commit:
git diff
- Alternatively, you can use the
--stagedoption to view the differences between your staged changes and the last commit:
git diff --staged
This is the result of completing step 2:
diff --git a/file1.txt b/file1.txt
index bfccc4a..ee23125 100644
--- a/file1.txt
+++ b/file1.txt
@@ -1 +1,2 @@
This is file1.
+hello,labex
This is the result of completing step 3:
diff --git a/README.md b/README.md
index 0164284..f47591b 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,3 @@
## git-playground
Git Playground
+hello,world
Summary
In this challenge, you learned how to view differences between staged or unstaged changes and the last commit using the git diff command. This feature is useful when you want to review your changes before committing them or when you want to see what changes you have made since the last commit. Keep practicing and exploring Git to become a proficient developer.