Themes

Version Control Systems

Version Control Systems

Making dumb mistakes faster, without fear

Coffee

Adrien Thebo

© 2012 Adrien Thebo CC BY-NC-SA 3.0

Introduction

What is Version Control?

Why Should You Care?

Why Should You Care?

Why Should You Care?

Background

Before VCS

Living dangerously!

nano really_complex_algorithm.c

three hours later:

rm -rf *

Whoops.

Do It Yourself VCS

Early implementations of version control was done by copying files

nano really_complex_algorithm.c
cp really_complex_algorithm.c really_complex_algorithm.c.1
nano really_complex_algorithm.c
cp really_complex_algorithm.c really_complex_algorithm.c.2
nano really_complex_algorithm.c
cp really_complex_algorithm.c really_complex_algorithm.c.3

This wouldn’t get tedious at all!

The beginning of VCS

Requirements for VCS

A Tour of Version Control Systems

Source Code Control System (SCCS)

Wikipedia: Source Code Control System

Revision Control System (RCS)

Wikipedia: Revision Control System

Pros and Cons of RCS

RCS in action

co -l agenda.txt <-- check out and lock a file
nano agenda.txt
ci -u agenda.txt <-- check in and unlock a file

Centralized VCS

Modern VCS

Concurrent Version System (CVS)

Applications of CVS Today

Pros and Cons of CVS

SVN

Apache Subversion (SVN)

Features of SVN

SVN Terms

TODO

Example SVN Structure

svn

Pros and Cons of SVN

Decentralized VCS

Decentralized VCS

DVCS compared to CVCS

Differences

Advantages

Disadvantages

  1. Git
  2. Mercurial
  3. Arch
  4. Darcs
  5. Bazaar

Git

Introduction to Git

I’m an egotistical bastard, and I name all my projects after myself. First Linux, now git.

Linus Torvalds

The inspiration for Git

Take CVS as an example of what not to do; if in doubt, make the exact opposite decision.

Characteristics of Git

Single Player Git

Git - Creating a Project

adrien@dre:~$ git init
Initialized empty Git repository in /private/vcs_presentation/.git/

This creates a new project in the current directory.

adrien@dre:~$ ls -la
total 264
drwx------  13 adrien  admin    442 Feb 24 17:52 ./
drwx------   9 adrien  admin    306 Feb 23 22:41 ../
drwx------  15 adrien  admin    510 Feb 24 17:52 .git/ <--- git init creates this directory
-rw-------   1 adrien  admin    249 Feb 24 17:45 Makefile
drwx------   5 adrien  admin    170 Feb 24 17:45 images/
-rw-------   1 adrien  admin  14330 Feb 24 17:52 vcs_presentation.text

Git - adding a file

git add lib/vunderbeam.rb

Git - seeing the project status

% git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#	new file:   lib/vunderbeam.rb

Git - seeing what content changed

adrien@dre:~$ git diff lib/vunderbeam
diff --git a/lib/vunderbeam.rb b/lib/vunderbeam.rb
index 7042555..48ce445 100644
--- a/lib/vunderbeam.rb
+++ b/lib/vunderbeam.rb
@@ -2,8 +2,8 @@ class Vunderbeam

   def initialize(opts = {:ios => $stdout, :sep => " | "})
     @widgets = []
-    @ios     = opts[:ios]
-    @sep     = opts[:sep]
+    @ios     = opts[:ios] || $stdout
+    @sep     = opts[:sep] || " | "
   end

Git - making your changes permanent

adrien@dre:~$ git commit -m 'Check out my awesome commit!'
[master (root-commit) 6735123] Check out my awesome commit!
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 example

Git - viewing the log of changes

adrien@dre:~$ git log
commit ccf7859df622b4f0f9e98bd38621f287f8a8218b
Author: Adrien Thebo <adrien@somethingsinistral.com>
Date:   Fri Feb 24 17:59:22 2012 -0800

    better grepping

OR

adrien@dre:~$ git log --oneline
a2667bf Don't log output for moving /etc/hosts
ac0349b Initial implementation of hosts provisioner
4f7a6d6 Update networking schema
329deab Fix bug with vagrant config stomping
cab6cde Initial implementation of networking
7bc833a Align data
a45d4ec Move all provisioning steps out of vagrantfile

Git - viewing what actually changed

adrien@dre:~$ git whatchanged -1
commit 67351233d0cad08ebbd4586da6a952d78a26ed5d
Author: Adrien Thebo <adrien@somethingsinistral.com>
Date:   Fri Feb 24 18:02:22 2012 -0800

    Check out my awesome commit!

:000000 100644 0000000... 0996042... A  example

OR

commit e7800016874335ea110449f27c8c4548ec8ec267
Author: Adrien Thebo <adrien@somethingsinistral.com>
Date:   Fri Nov 9 21:46:10 2012 -0800

    Add default values for vunderbeam

diff --git a/lib/vunderbeam.rb b/lib/vunderbeam.rb
index 7042555..48ce445 100644
--- a/lib/vunderbeam.rb
+++ b/lib/vunderbeam.rb
@@ -2,8 +2,8 @@ class Vunderbeam

   def initialize(opts = {:ios => $stdout, :sep => " | "})
     @widgets = []
-    @ios     = opts[:ios]
-    @sep     = opts[:sep]
+    @ios     = opts[:ios] || $stdout
+    @sep     = opts[:sep] || " | "
   end

Branching and Merging with Git

Git - Branching and Merging, a visual representation

* fd1685b Adrien Thebo 3 months ago snaaarky comments.
* f461e29 Adrien Thebo 3 months ago Sketchy urls.
* a3cca2d Adrien Thebo 3 months ago Added gpg.
* c0cfcdd Adrien Thebo 3 months ago PLURALIZATION!
*   edf37aa Adrien Thebo 3 months ago Merge branch 'css_work'
|\
| * fda5612 Adrien Thebo 3 months ago Block quoting quotes
| * 8d7ca85 Adrien Thebo 3 months ago Try to fix CSS
| * 27e6cf2 Adrien Thebo 3 months ago Usage of backticks instead of single quotes
| * c52996f Adrien Thebo 3 months ago Brief introductions to the sections on the index
* | 48d3834 Adrien Thebo 3 months ago Definitions or something like that.
|/
* ffe5bb6 Adrien Thebo 3 months ago Renamed preamble to reasoning
* 8851dae Adrien Thebo 3 months ago cleanup on redirection

Git - Looking at current branches

adrien@dre:~$ cd src/facter
adrien@dre:~$ git branch
* 1.6.x
  external_fact_support_full
  master
  proto/master/docstrings
  ticket/1.6.x/12813-redirect_lspci_stderr
  ticket/11660-sshfp_and_ssh_rspec
  ticket/master/2157-external_fact_support
  ticket/master/4561-add_structured_data

Git - Making a new branch

adrien@dre:~$ git branch new_feature_branch

This creates the branch ‘new_feature_branch’

adrien@dre:~$ git branch
* 1.6.x
  external_fact_support_full
  master
  new_feature_branch  <------ We made a new branch!
  proto/master/docstrings
  ticket/1.6.x/12813-redirect_lspci_stderr
  ticket/11660-sshfp_and_ssh_rspec
  ticket/master/2157-external_fact_support
  ticket/master/4561-add_structured_data

Note that we’re still on the 1.6.x branch

Git - Making a new branch

Alternately…

adrien@dre:~$ git checkout -b another_feature_branch
Switched to a new branch 'another_feature_branch'

This creates a new branch and switches to it.

adrien@dre:~$ git branch
  1.6.x
* another_feature_branch  <---- Another new branch! Note the asterisk!
  external_fact_support_full
  master
  new_feature_branch
  proto/master/docstrings
  ticket/1.6.x/12813-redirect_lspci_stderr
  ticket/11660-sshfp_and_ssh_rspec
  ticket/master/2157-external_fact_support
  ticket/master/4561-add_structured_data

The asterisk indicates that this is our current branch.

Git - Working in a branch

Git - Merging a branch

In this example, I’ll merge the branch ‘duplicity’ into the main branch, ‘master’.

adrien@dre:~$ git branch
* duplicity
  ganeti
  master
adrien@dre:~$ git checkout master
Switched to branch 'master'
% git merge duplicity
Merge made by recursive.
 dist/duplicity/manifests/cron.pp |   70 ++++++++++++++++++++++++++++++++-----
 1 files changed, 60 insertions(+), 10 deletions(-)

The resulting history looks like this:

*   413e4a7 Adrien Thebo 3 minutes ago Merge branch 'duplicity'
|\
| * d6b7efc Adrien Thebo 3 hours ago Force removal of stale backup files
| * 39d6423 Adrien Thebo 4 hours ago Echo date to duplicity last run file instead of touching
| * 14f7e30 Adrien Thebo 4 hours ago Remove unneeded inline_template from duplicity::cron
| * affa757 Adrien Thebo 4 hours ago Add incremental, full backups + cleanups for duplicity
|/
* f83a636 Adrien Thebo 5 hours ago Typo in duplicity for gpg agent info

Git - Why Would You Use Branches?

Many projects require features be implemented in a branch

Multiplayer Git with Github

Github - Copying a project as read-only

    adrien@dre:~$ git clone git://github.com/adrienthebo/worstprogramever
    Cloning into worstprogramever...
    remote: Counting objects: 20, done.
    remote: Compressing objects: 100% (19/19), done.
    remote: Total 20 (delta 5), reused 9 (delta 1)
    Receiving objects: 100% (20/20), done.
    Resolving deltas: 100% (5/5), done.

Github - Copying a project as read-write

    adrien@dre:~$ git clone git@github.com:adrienthebo/worstprogramever
    Cloning into worstprogramever...
    remote: Counting objects: 20, done.
    remote: Compressing objects: 100% (19/19), done.
    remote: Total 20 (delta 5), reused 9 (delta 1)
    Receiving objects: 100% (20/20), done.
    Resolving deltas: 100% (5/5), done.

Github - Making changes to a project

Make your changes as normal…

adrien@dre:~$ nano README.markdown
adrien@dre:~$ git add README.markdown
adrien@dre:~$ git status
## master
A  README.markdown
adrien@dre:~$ git ci
[master 3534eef] Added a README!
 1 files changed, 25 insertions(+), 0 deletions(-)
 create mode 100644 README.markdown

And then run git push

adrien@dre:~$ git push
Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 605 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:adrienthebo/worstprogramever
   29e5bcd..3534eef  master -> master

This uploads your branch to the remote server, so you can share it with people.

Git internals

Git internals

No one part of git is especially complicated.

Too bad there are so many parts…

WARNING

This stuff is complex, and isn’t necessary to get up and running. Don’t worry if it isn’t immediately clear.

Implementation

Why hash everything?

The building blocks of Git

Blob

Blob

Tree

Tree

Commit

Commit

Tag

Tag

Putting it all together

Objects

Git concepts

The working directory

References

The index

Git workflow and commands

Git workflow

Workflow

Changing files with git

Viewing git information

Branching and merging

Making changes to the history

Collaboration

Advanced Git

Git hooks

The really gory details

This slide will be completed someday.

HAHAHAHA no.

References

Find this Presentation

/

#