git diff
- Git course
- Beginner
- Lesson 33/80
- 4 min
Learn to view changes with git diff.
View file changes
git diff displays changes in the working tree that have not been staged. After editing a file, you can use this command to inspect which lines have changed. It compares the current file contents with the last staged state.
git diffThis allows you to review your edits before creating a commit.
Read diff output
In git diff output, lines beginning with + represent added content, while lines beginning with - represent removed content. The section marked with @@ indicates which file lines are involved in the change.
-Hello
+Hello GitIn this example, the old line was removed and replaced with a new line.
Practice Display changes in the terminal
Write the git diff command to view unstaged changes in the working tree.
Starter code
# Sahnelenmemiş değişiklikleri göster
# Komutu buraya yazSample solution
# Sahnelenmemiş değişiklikleri göster
git diffExpected output
git diff komutu çalıştırılır
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 You edited a file but have not used git add yet. Which command should you run to see the changes?
- git status --short
- git commit
- git diff Correct answer
- git init
Explanation: <code>git diff</code> displays unstaged changes in the working tree.
2 Complete the diff command name
git d____
git diff
Explanation: <code>git diff</code> displays unstaged changes in the working tree.
3 Diff output markers
| Term | Meaning |
|---|---|
+ satırı |
Added content |
- satırı |
Removed content |
@@ |
Line location information |
Working tree |
Current working files |