~/
hackweb.dev
Viewing Changes
Quiz
⌘K
...
~/
/tutorials
/git/git-diff/edit
~ Contribute
Suggest a correction or improvement. The author reviews it before it goes live.
Loading...
Comment
0 / 300
Typo
Grammar
Broken link
Clarify
Code
en/tutorials/git/6git-diff
Write
Preview
Diff
# Viewing Changes `git diff` shows what changed between different states of your repository. It's essential for reviewing changes before committing. ## Unstaged Changes See changes not yet staged: ```bash git diff # diff --git a/file.txt b/file.txt # --- a/file.txt # +++ b/file.txt # @@ -1 +1 @@ # -old line # +new line ``` ## Staged Changes See changes that are staged for commit: ```bash git diff --staged ``` ## All Changes See everything (staged and unstaged): ```bash git diff HEAD ``` ## Statistical Summary Get a quick overview of what changed: ```bash git diff --stat # file.txt | 2 +- # 1 file changed, 1 insertion(+), 1 deletion(-) ``` ## Reading Diff Output - `-` lines show what was removed - `+` lines show what was added - `@@` shows the line range affected - Colors help distinguish additions (green) from deletions (red) ## Best Practices - Review changes with `git diff` before staging - Use `git diff --staged` before committing - Use `git diff --stat` for quick overviews - Compare specific commits with `git diff commit1 commit2` ## Common Mistakes - Not reviewing changes before committing - Confusing staged and unstaged diffs - Ignoring whitespace changes that affect functionality - Not using diff to understand merge conflicts
No changes yet
Reset to original
Submit suggestion
cancel