Chapters & contents Lesson 19 of 19
3 min read
Git and Linux workflowExpanded reading

Inspect a change before turning it into history

Connect shell commands, process results, and Git’s working tree and index.

What you’ll learn

  • Distinguish file edits, staged content, and committed history
  • Inspect a process result without confusing output with success
  • Use a reviewable sequence for a small contribution

Know which tool owns the state

The shell starts programs and connects their input and output. Git records snapshots and relationships between commits. Editing a file changes its contents on disk, but it does not automatically stage or commit those bytes. Running a successful Git command does not prove the application behaves correctly either. Keep the responsibilities separate: inspect the filesystem change, choose the snapshot to record, and run an appropriate check for the behavior you changed. This distinction makes debugging a contribution much less mysterious.

Trace one file through three states

Begin with a committed lesson containing the word variable. Change it to binding and run git diff: the difference appears between the working tree and index. Stage the file, then run git diff --staged to inspect the proposed commit. Now make one more unstaged edit to a heading. A commit records the staged version, not that final heading edit. The same file can therefore have staged and unstaged changes at the same time. Always inspect the staged patch when deciding what a commit will contain.

bash · Worked example
git status
git diff
git diff --staged

Read results as well as printed text

Programs usually signal success to the shell with exit status zero and report failure with a nonzero status. Their standard output and standard error are separate streams, and a program can print useful text before failing. In Bash, the status of a pipeline normally comes from its last command unless pipefail is enabled. A formatter piped into another command can therefore appear successful even when an earlier step failed. Understand the chosen shell’s behavior before using a compact pipeline as a validation gate.

Build a safe contribution loop

Use git status to see the current branch and changed files, inspect the relevant diff, and keep unrelated edits outside the proposed change. Run the smallest meaningful validation for the modified lesson or code. Stage explicit paths when that helps keep the scope clear, inspect the staged diff again, then write a commit message that describes the resulting behavior. If a command fails, read its diagnostic and inspect state before repeating it. Blind repetition can make the original problem harder to identify.

Make history useful to another maintainer

A useful commit groups changes that can be understood and reviewed together. For a lesson correction, include enough context in the message or pull request to explain the misconception and the new example. Do not commit credentials, personal environment files, generated noise, or someone else’s unrelated work. Practice the workflow in a disposable repository with one text file before applying more advanced history operations. The goal is a clear, recoverable explanation of change, not memorization of a long list of commands.

Try it yourself

You edit a file, stage it, and then edit it again. Which version does the next commit record? Name two read-only commands that show the two different patches.

Show a possible solution

The next commit records the staged snapshot. git diff shows working-tree changes relative to the index, and git diff --staged shows staged changes relative to the current commit. Review both before deciding whether the final edit belongs in the commit.

Check your understanding

Try 14 questions across git and linux workflow. Read each explanation and revisit anything that needs another pass.

Practise this subject

Go to the source

Use these primary references to check details and explore the topic further.

Saved in this browser. Signed-in progress syncs to your account.