22
98-174 F15 Modern Version Control with Git Andrew Benson [email protected] https://www.andrew.cmu.edu/course/98-174/ Sign in on the attendance sheet!

98-174 F15 Modern Version Control with Git Andrew Benson [email protected] Sign in on the attendance sheet!

Embed Size (px)

Citation preview

Page 1: 98-174 F15 Modern Version Control with Git Andrew Benson adbenson@andrew.cmu.edu  Sign in on the attendance sheet!

98-174 F15Modern Version Control with Git

Andrew [email protected]

https://www.andrew.cmu.edu/course/98-174/

Sign in on the attendance

sheet!

Page 2: 98-174 F15 Modern Version Control with Git Andrew Benson adbenson@andrew.cmu.edu  Sign in on the attendance sheet!

Why should you take this course?

To become smarter than Fox News

Page 3: 98-174 F15 Modern Version Control with Git Andrew Benson adbenson@andrew.cmu.edu  Sign in on the attendance sheet!

Git ≠ Github

Page 4: 98-174 F15 Modern Version Control with Git Andrew Benson adbenson@andrew.cmu.edu  Sign in on the attendance sheet!

What this course isn’t

• For seasoned Linuxbeards

Page 5: 98-174 F15 Modern Version Control with Git Andrew Benson adbenson@andrew.cmu.edu  Sign in on the attendance sheet!

What this course isn’t

• A crashcourse on git commands

Page 6: 98-174 F15 Modern Version Control with Git Andrew Benson adbenson@andrew.cmu.edu  Sign in on the attendance sheet!

What this course is about

• Forming a mental model for how git interacts with versions of files• Understanding how to use git (and a bit of Github) in a collaborative

setting

Page 7: 98-174 F15 Modern Version Control with Git Andrew Benson adbenson@andrew.cmu.edu  Sign in on the attendance sheet!

Grade Breakdown

Pass/No Credit, like every StuCo. To pass, get 70% out of:• 20% Weekly Lectures (Thursdays 6:30-7:20 pm, Porter Hall 126A)• 30% Weekly Homework (due following lecture, turned in via git,

except the first few weeks, which will be via email)• 20% Midterm (Date TBA)• 30% Final (Date TBA)

Page 8: 98-174 F15 Modern Version Control with Git Andrew Benson adbenson@andrew.cmu.edu  Sign in on the attendance sheet!

More Course Details

• Prerequisite: Basic Unix Survival• 3 Free Elective credits• No official textbook, but I recommend Pro Git by Scott Chacon• No office hours• Piazza• Slides and lecture notes posted online

Page 9: 98-174 F15 Modern Version Control with Git Andrew Benson adbenson@andrew.cmu.edu  Sign in on the attendance sheet!

Course Policy

• By StuCo Policy, students with more than 2 unexcused absences must be given a No Pass in the course. Thus, tell me if you’re going to miss class for a legitimate reason, and you might get an excused absence.• More than 15 minutes late = unexcused absence• Academic integrity applies. Don’t cheat.• No late homework.

Page 10: 98-174 F15 Modern Version Control with Git Andrew Benson adbenson@andrew.cmu.edu  Sign in on the attendance sheet!

Waitlists

Page 11: 98-174 F15 Modern Version Control with Git Andrew Benson adbenson@andrew.cmu.edu  Sign in on the attendance sheet!

The Problem – “Version Control”

• I want to be able to go back to any prior version of any file in my project• I want to be able to easily share a change to my project with someone

else who has an older version

Page 12: 98-174 F15 Modern Version Control with Git Andrew Benson adbenson@andrew.cmu.edu  Sign in on the attendance sheet!

Emailing Tars

• Memory-intensive• Can be slow• Can be hard to track

Page 13: 98-174 F15 Modern Version Control with Git Andrew Benson adbenson@andrew.cmu.edu  Sign in on the attendance sheet!

Diff and Patch• Idea: store only one version of each file, and store diffs between

different file versions

Page 14: 98-174 F15 Modern Version Control with Git Andrew Benson adbenson@andrew.cmu.edu  Sign in on the attendance sheet!

Diff and Patch

• Apply and reverse-apply diffs to retrieve the needed version of the file• Instead of sharing entire tars,

developers share a diff file (“patch”) for each changed file• Faster, uses less memory, but

inconvenient because it’s dependent on order of applying patches when there are many patches

Page 15: 98-174 F15 Modern Version Control with Git Andrew Benson adbenson@andrew.cmu.edu  Sign in on the attendance sheet!

Centralized Version Control Systems

• A central, blessed repository determines the order of patches/commits• If a commit directly precedes another

commit in this order, then it is the parent commit of that other commit (so A is the parent of B)• Any new commits must be compatible

with the latest commit. If accepted, it becomes the latest commit’s child original file

from my project

Patch A

Patch C

Patch B

Patch Z

Central, Blessed Repository

Patch α

Any new patches must be compatible with the latest version of the

central repo, Patch Z

Page 16: 98-174 F15 Modern Version Control with Git Andrew Benson adbenson@andrew.cmu.edu  Sign in on the attendance sheet!

Distributed Version Control Systems• No central repository• Every repository has every commit

Central Repositor

y

Developer A’s local files

Developer D’s local files

Developer C’s local files

Developer B’s local files

Commit

Checkout

Checkout

Commit

Commit

Commit

Checkout

Checkout

Dev A’s Repo

Dev B’s Repo

Dev C’s Repo

Dev D’s Repo

Commit Commit

Commit

Commit

Push/Fetch

Push/Fetch

Push/Fetch

Push/FetchPush/

Fetch Push/Fetch

Centralized Version Control

System

Distributed Version Control

System

Page 17: 98-174 F15 Modern Version Control with Git Andrew Benson adbenson@andrew.cmu.edu  Sign in on the attendance sheet!

Git

• Created in 2005 by Linus Torvalds to maintain the Linux kernel. Oh, and he also created that too.• DVCS

Page 18: 98-174 F15 Modern Version Control with Git Andrew Benson adbenson@andrew.cmu.edu  Sign in on the attendance sheet!

Changes: Project-Tracking, No Diffs• Other VCSs track changes to individual files• Git tracks changes to the project, so commits can change more than one file• Also, git doesn’t actually keep diffs around like other VCSs - it keeps a copy of every file

from every commit, and uses magic and compression to keep the repo fast and small• So think of the git history as a series of snapshots of what the repository looked like at

each commit. You can retrieve files from any commit

Commit 1:

A_v1.txtB_v1.txt

Commit 2:

A_v2.txtB_v1.txt

Commit 3:

A_v3.txtB_v2.txt

Commit 4:

A_v3.txt

Commit 5:

A_v4.txtC_v1.txt

Page 19: 98-174 F15 Modern Version Control with Git Andrew Benson adbenson@andrew.cmu.edu  Sign in on the attendance sheet!

Git Clone

Example use:git clone https://github.com/torvalds/linux

• Creates a copy of the entire repository on your computer

Page 20: 98-174 F15 Modern Version Control with Git Andrew Benson adbenson@andrew.cmu.edu  Sign in on the attendance sheet!

Git Log

Example use:git log

• Lists all the previous commits made up to the current commit

Page 21: 98-174 F15 Modern Version Control with Git Andrew Benson adbenson@andrew.cmu.edu  Sign in on the attendance sheet!

Demo

Page 22: 98-174 F15 Modern Version Control with Git Andrew Benson adbenson@andrew.cmu.edu  Sign in on the attendance sheet!

Homework

• Make a Github account• Clone Angular• Answer the homework questions, which will be posted this weekend