UP | HOME

Version Control
Tools
COP-3402

Table of Contents

Version control

Records changes to code (or any file)

Why use version control?

  • Large, complicated code base
  • Many developers working together
  • Tracking causes of bugs
  • Rewind history to prior versions
  • Log who made code changes

Bank account balance

TOTAL $31

Says nothing about how you got there. Why do I only have $31?

  • Did I spend too much this week?
  • Did I not get paid?

Bank account transactions

Description Amount
Income $42
Gas -$15
Food -$6
Reimbursement $10
TOTAL $31

Transactions are (generally) append-only. You only add transactions.

You can always reconstruct the total from your transactions.

Version Control Systems

  • Record each version to a log
  • Document developer descriptions of change

diff

diff hello.c new_hello.c

Displays only

  • lines added
  • lines removed

A diff is like a bank transaction. It only contains what has changed in the new files (lines added or removed).

Examples:

  • diff oldhello.c newhello.c
  • git diff …

patch

diff hello.c new_hello.c > change.patch
cp hello.c patched_hello.c
cat patched_hello.c 
patch patched_hello.c change.patch 
cat patched_hello.c

patch is a companion tool that takes diff files and applies them to the oldfile to get the new file.

patch -R file.c change.patch

Version history

Sequence of diffs

Diagram

Conceptually, can think of version history as a sequence of diffs, with metadata, like a description, author, date, etc. Additionally, the diff points to the previous version.

Just like a bank balance equals a sequence of transactions, the sequence of diffs applied in order equals the current version.

git

Sections of a git project

Section Description State of a Change
Working directory A copy of one version Modified
Staging area Collects changes Staged
Local repository Stores all versions Committed
Remote repository Stores all versions Pushed

(Diagram)

  • This is where you edit source files
  • This the .git subdirectory in your working directory

Sections of a git project

areas.png

https://git-scm.com/book/en/v2/Getting-Started-What-is-Git%3F

  • Committed means the changes are logged in the repository
  • Staged means specific changes have been marked for commit
  • Modified means the files in your working directory (where you edit your files) differ compared to the last version in the repository

Distributed version control

Changing state

Operation Description Where
emacs Modify a file Working directory
git add Stage a file Staging area
git commit Commit a change Local repository
git push Synchronize changes Remote repository

vc exercise

Author: Paul Gazzillo

Created: 2025-10-15 Wed 10:00