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 old_file.c new_file.c > change.patch

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

cp old_file.c file.c
cat file.c 
patch file.c change.patch 
cat file.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

Changing state

Operation Description Where
emacs/vim 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

git exercise

Author: Paul Gazzillo

Created: 2024-12-19 Thu 14:37

Validate