my-notes

git_status_and_diff

1 min read

git status & diff

Check repository state and view changes.


πŸ“Š git status

Full Status

git status

Shows the state of working directory and staging area.


Short Status

git status -s

Shows compact status. First column = staging, second column = working tree.

Symbols:

  • M = Modified
  • A = Added
  • D = Deleted
  • ?? = Untracked
  • R = Renamed

Short Status with Branch

git status -sb

Shows short status with branch information.


Show Ignored Files

git status --ignored

Also shows files that are being ignored by .gitignore.


πŸ“Š Status Output Meaning

graph TD
    A[git status output] --> B[Changes to be committed]
    A --> C[Changes not staged]
    A --> D[Untracked files]
    B -->|Staged| E[Ready for commit]
    C -->|Modified| F[Need git add]
    D -->|New files| G[Need git add]

πŸ” git diff

View Unstaged Changes

git diff

Shows changes in working directory that are not yet staged.


View Staged Changes

git diff --staged

Shows changes that are staged and will go into next commit.


Staged Changes (Alternative)

git diff --cached

Same as --staged. Shows what will be committed.


Diff Specific File

git diff filename.txt

Shows changes only for filename.txt.


Diff Between Commits

git diff abc1234 def5678

Shows differences between two commits.


Diff Between Branches

git diff main feature-branch

Shows differences between two branches.


Diff Current vs Branch

git diff main

Shows differences between current branch and main.


Diff HEAD vs Working Directory

git diff HEAD

Shows all changes (staged and unstaged) since last commit.


Show Only File Names

git diff --name-only

Lists only the names of changed files.


Show Names with Status

git diff --name-status

Lists file names with modification type (M/A/D/R).


Show Statistics

git diff --stat

Shows summary of changes: files changed, insertions, deletions.


Word-level Diff

git diff --word-diff

Shows differences at word level instead of line level.


Ignore Whitespace

git diff -w

Ignores all whitespace changes.


Diff with Color Words

git diff --color-words

Highlights changed words in color, not entire lines.


πŸ“Š Diff Flow

graph LR
    A[Working Dir] -->|git diff| B[vs Staged]
    B -->|git diff --staged| C[vs Last Commit]
    A -->|git diff HEAD| C

πŸ’‘ Tips

Quick Check Before Commit

Always run git diff --staged before committing to review changes.

Save Diff to File
git diff > changes.patch


#git #status #diff #basics

Built with mdgarden