Course Homepage

Version Control

Version control

Records changes to code (or any file)

Why use version control?

Bank account balance

Description Amount
TOTAL $31

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

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

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:

patch

diff hello.c new_hello.c > change.patch
patch hello.c change.patch -o patched_hello.c
cat patched_hello.c

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

To reverse a change: 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

Pro Git.

Link to the Pro Git book

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)

Sections of a git project

Git areas.

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

Distributed version control

Distributed version control.

https://git-scm.com/book/en/v2/Getting-Started-About-Version-Control

Full repository copies on each machine

Changing state

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

How operations change state

Git project life cycle.

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

vc exercise

vc exercise