Sub topic 1
Why Version Control Exists
Prerequisites
This chapter assumes you can do the following:
- Work with files and folders on your computer.
- Open a terminal or command prompt.
- Run simple shell commands.
You do not need to know Git yet. This chapter explains the problem that version control solves. Later chapters cover Git itself.
The problem: files change and history gets lost
Any project that lives in files changes over time. You edit a document, rewrite a function, or adjust a configuration. Each edit raises the same questions:
- What did this file look like last week?
- Who changed this line, and why?
- How do I undo a change that turned out to be wrong?
- How do several people edit the same files without overwriting each other?
Without a tool, people answer these questions by hand. They copy folders and rename them, and they email attachments back and forth.
report.docx
report_v2.docx
report_v2_final.docx
report_v2_final_REALLY_final.docxThis habit works for one person on a tiny project. It breaks down quickly:
- Names do not say what changed or why.
- Copies pile up and eat disk space.
- Nobody knows which copy is the current one.
- Two people editing separate copies must merge their work by hand, and mistakes are easy to make.
What version control is
A version control system (VCS) is software that records changes to a set of files over time. It lets you recall specific versions later. The set of files and their recorded history is usually called a repository.
A version control system gives you these abilities:
- History. Every saved change is recorded with a timestamp, an author, and a message.
- Undo. You can return a file, or the whole project, to an earlier state.
- Comparison. You can see exactly what differs between two versions.
- Collaboration. Several people can work on the same project in parallel, and the system helps combine their changes.
- Experimentation. You can try an idea on a separate line of work and keep it only if it succeeds.
A unit of recorded change is called a commit in Git and in many other systems. You will make your first one in a later chapter.
Who uses it and why
Software teams are the best-known users. A large codebase may have hundreds of contributors, and the history explains why the code looks the way it does. Version control also helps individuals. A solo developer gains a safety net and a record of their own decisions.
Other work benefits as well. Configuration files, documentation, data analysis scripts, and written text all fit well. Plain text files work best, because the system can show line-by-line differences. Large binary files such as videos are harder to handle, though they can still be tracked.
A typical workflow
The diagram shows the general cycle in any version control system. The details differ between tools, but the shape stays the same.
You edit files, review what changed, and record a version with a short message. The history grows with each recorded version. At any point you can look back at it, compare versions, or restore an older one.
What good messages and small changes give you
The value of the history depends on how you record it. Two habits matter from the start:
- Record small, focused changes. A change that does one thing is easy to review and easy to undo.
- Write clear messages. A message such as "Fix rounding error in invoice total" helps your future self. A message such as "stuff" does not.
What version control is not
Version control is not a backup system. A backup copies your files to a second location to protect against loss. A repository on one disk is lost if that disk fails. Version control tools can be combined with remote copies of a repository, but you should not assume history is safe until you have copies elsewhere.
It is also not a replacement for communication. The system can combine changes, but it cannot decide which of two conflicting edits is correct. People still have to resolve those cases.
Common misunderstandings
- "It saves every keystroke." It does not. It records versions only when you ask it to.
- "It is only for programmers." Anyone who works with text files can use it.
- "A copy of the folder is the same thing." A copy holds one state. A version control system holds the relationships between many states, including who changed what.
Where this leads
The next chapter compares the three main designs for version control systems: local, centralized, and distributed. Knowing how they differ explains why Git works the way it does and why its commands behave as they do.
Exercise
Name two problems with managing versions by copying and renaming files, and one capability a version control system adds that solves them.
Show answer
Examples of problems: file names do not say what changed or why, and copies pile up so nobody knows which is current. Merging two people's separate copies by hand is also error-prone. A version control system adds a recorded history with authors, timestamps, and messages, and it lets you compare versions and restore an earlier one. It also helps combine changes from several people.
Exercise
Why is a repository on a single laptop not a complete backup?
Show answer
If the laptop's disk fails or the laptop is lost, the files and the whole history are lost together. A backup needs a copy stored in a separate location.