Sub topic 1
Why Track Changes with Version Control
Version control is a system that records changes to files over time, so you can review, compare, and restore earlier states. This chapter explains the problem it solves and the vocabulary the rest of the tutorial relies on. You will not run Git commands yet.
Prerequisites
This chapter assumes you have:
- Comfort using a terminal and basic shell commands such as
cd,mkdir, andls. - The ability to create and edit plain text files.
- Git installed on your machine.
The problem: files change and history is lost
Without version control, people keep history by hand. They copy files and rename them report_final.txt, report_final2.txt, and report_really_final.txt. This approach has predictable failures:
- You cannot tell what differs between two copies without opening both.
- You cannot tell why a change was made.
- Two people editing copies must merge their work by hand.
- A mistake discovered a week later may have no clean copy to return to.
A version control system replaces the copies with one tracked history. Each saved state is recorded with its author, a timestamp, and a message that explains the change.
What version control gives you
| Capability | What it means in practice |
|---|---|
| History | Every recorded state of the project can be listed and inspected. |
| Comparison | You can see exactly which lines changed between two states. |
| Recovery | You can return to a known good state after a mistake. |
| Attribution | Each change records who made it and when. |
| Collaboration | Several people can work on the same project and combine their changes. |
Why Git is different from older systems
Git is a distributed version control system. Every copy of a project, called a repository, holds the full history. You can commit, view history, and compare versions without a network connection. Older centralized systems kept history on one server, and most operations needed to contact it.
A repository is a project's files together with the recorded history of their changes. Git stores that history in a hidden directory named .git inside the project. The next chapter looks at what lives there.
A deliberate two-step way of saving
Many tools save everything in one step. Git splits recording a change into two steps:
- You choose which changes to include. This is called staging.
- You record the chosen changes as a commit, a snapshot of the project with a message.
The split lets you make several unrelated edits and still record them as separate, focused commits. The remaining chapters build on this idea.
Common misunderstandings
- Version control is not a backup. A repository on one disk is lost if the disk fails. Copies of the repository on other machines protect against that.
- Version control is not only for code. It works best on plain text files, such as source code, documentation, and configuration, but it can also track other files.
- A commit is not automatic. Git records only what you explicitly commit. Edits you never commit cannot be restored from history.
Summary
Version control replaces manual file copies with a single history of changes. Git stores that history in a repository on your own machine, and it records changes in two steps: stage, then commit.
Exercise
A teammate says, "I keep my project in a Git repository, so I don't need backups." Give one reason this is risky, and one thing Git does record that file copies named final2 do not.
Show answer
A repository on a single disk is lost if that disk fails, and edits that were never committed are not in the history. Git records the author, the timestamp, and a message explaining each change, which renamed copies do not.