Monash University · FACULTY OF COMPUTER SCIENCE

FIT2109 Chap.4 Git Foundations

- one subject, every graph, every model, every mark
8 Chapters4-page Bible
Our own words - no uploaded lecturer files
Updated for this semester
Chapter 4 of 12 · FIT2109

Git Foundations

Git Foundations is built around three states. The working tree contains editable files, the index contains the proposed next snapshot, and the repository contains recorded commits. A commit records the index.

This explains why a pathname can appear under both staged and unstaged changes: the indexed version differs from the current commit, while newer working-tree content also differs from the index.

A useful history is made from focused snapshots whose purpose can be reviewed. Stage deliberately, inspect the staged diff and write messages that describe the behaviour changed. Recovery also follows from the state model.

Decide which layer should change and which version must be preserved before choosing an operation.

In this chapter

What this chapter covers

  • 01

    Repository snapshots connected by parent relationships

  • 02

    Working-tree files as the editable project state

  • 03

    The index as the proposed next snapshot

  • 04

    Status as two comparisons presented together

  • 05

    Focused commits that preserve a development narrative

  • 06

    Commit messages that describe purpose rather than activity

  • 07

    Selective staging and staged-diff review

  • 08

    Recovery choices that target the intended layer

Worked example · free

Explain a file listed twice by status

Q [6 marks]. A status report lists parser.py under changes to be committed and under changes not staged. Explain the state precisely and state what happens if a commit is created immediately. The marks used in this prompt are not an official University mark allocation; AskSia provides them for staged-state practice.
  • +1Identify the current commit, index and working-tree versions as separate states.
  • +1Explain that the indexed parser.py differs from the version in the current commit.
  • +1Explain that the working-tree parser.py also differs from the indexed version.
  • +1Infer that the file was staged and then edited again, or was staged partially.
  • +1State that an immediate commit records the indexed version.
  • +1State that the newer unstaged content remains in the working tree after the commit.
Git is presenting two comparisons. The index differs from the current commit, so parser.py is staged. The working-tree file also differs from the index, so newer content remains unstaged. Committing now records the indexed snapshot and leaves the later working-tree changes uncommitted.
Sia tip — Do not say only that the file changed twice. Name the two comparisons and the version that the next commit will record.
Glossary

Key terms

Repository
Git's recorded commit graph and related objects. Commits preserve snapshots linked to one or more parents.
Working tree
The checked-out files available for editing. Saved changes here are compared with the index to report unstaged differences.
Index
The staged snapshot that a new commit will record. It can contain a different version from both the current commit and working tree.
Commit
A recorded snapshot with metadata and parent links. A focused commit should represent one coherent behavioural change.
Staged change
A difference between the current commit and the index. It is included in the next commit unless the index changes first.
Unstaged change
A difference between the working tree and index. It remains outside the next commit until staged.
Selective staging
Choosing particular files or hunks for the index so one commit can preserve a coherent purpose without unrelated edits.
FAQ

Git Foundations FAQ

Why is the index more than a list of filenames?

It stores the content proposed for the next snapshot. A file can be staged and then edited again because the index preserves the earlier version while the working tree moves onward.

What should I inspect before committing?

Save intended buffers, run the relevant verification, inspect the working-tree diff and inspect the staged diff. The staged view is the direct evidence of what the commit will contain.

What makes a strong commit message?

It states the observable purpose, such as preserving spaces in input paths, and can explain a non-obvious cause or trade-off. Repeating a filename adds little because the diff already shows the file list.

Why is undo ambiguous in Git?

You may want to change the working tree, index, a branch label or published history. Each goal preserves a different version, so name the target layer before selecting a recovery operation.

Study strategy

Assessment move

Draw three boxes labelled current commit, index and working tree. Create a repository where one file is edited, staged and edited again, then predict both diffs and the result of committing. Practise selective staging so one snapshot contains only a focused repair. Read each commit message beside its diff and rewrite vague messages into behaviour-focused subjects.

Next rehearse recovery with disposable files: remove a generated artifact from the index while keeping it locally, discard one local experiment while preserving staged content, and create a new commit that reverses an earlier published change. Before each action, state which layer must change and where the desired version currently exists. Finish by explaining the complete state model without commands.

If the model is clear, command selection becomes a consequence rather than a memory test. Add a drill where only part of one file is staged. Predict what the staged and unstaged diffs show, then commit and verify the remaining working-tree change. Create a safety branch before a recovery experiment and use the graph to prove the original snapshot remains reachable.

These exercises connect content selection with recoverability instead of treating staging as a checkbox.

Working through Git Foundations in FIT2109? Sia is AskSia’s AI Computer Science tutor — ask any FIT2109 Git Foundations question and get a clear, step-by-step explanation grounded in how FIT2109 is taught and assessed. Read this chapter free, then take your hardest questions to Sia.

A+Everything unlocked
Unlocks this Bible + all 167 of your Monash University subjects - and 1,000+ Bibles across every Australian university.
Sia - your FIT2109 tutor, unlimited, worked the way the exam marks it
The full 4-page Bible + practice bank with worked solutions
Chrome extension - sync your LMS so Sia knows your deadlines
Bilingual EN / Chinese on every Bible and every Sia answer
$0.99 Trial
30-day money-back · cancel in one tap · how it works