CHAPTER 6 : Review Staged or Unstaged File

Since we already know that git status helps us get info about operations, it can be a bit too descriptive.

If you want a more concise view of what changes you actually made, use:

git diff shows changes made to files that are not staged yet. It highlights lines added (green) and removed (red).

git diff --staged shows differences between the last commit and staged changes, which will be part of the next commit.


๐Ÿ“ฆ Git Workflow Visual

Understand where each command fits in the Git staging process:

    Working Directory โ”€โ”€[git add]โ”€โ”€โ–ถ Staging Area โ”€โ”€[git commit]โ”€โ”€โ–ถ Repository
         โ–ฒ                        โ–ฒ
         โ”‚                        โ”‚
     [git diff]          [git diff --staged]
            

๐Ÿ“š Real-Life Example

Imagine you're working on main.css and app.js:


    # Make changes to both files
    echo "body { color: red; }" >> main.css
    echo "console.log('Update');" >> app.js
    
    # Stage main.css only
    git add main.css
    
    # Run diffs
    git diff           # See changes in app.js (unstaged)
    git diff --staged  # See staged changes in main.css
        


๐Ÿงช Git Diff Visualizer

Select files and see what git diff and git diff --staged would show:





No files selected yet.

๐Ÿง  Quick Quiz

Q: You staged file1.txt but not file2.py. Which command shows changes in file2.py?