Slide 1

Slide 1 text

GIT VS. SVN Which one should we use and when? http://www.paradigmatecnologico.com @paradigmate http://marianonavas.me @marianongdev

Slide 2

Slide 2 text

What is a CVS for? • Allow team work together and collaborate • Have some kind of time machine in our code • Allow CI

Slide 3

Slide 3 text

Approaches (architectural models) • Local • Rcs (Mac OS Developer Tools) • Centralized • Subversion • CVS • Perforce • Distributed • Git • Mercurial

Slide 4

Slide 4 text

Approaches (architectural models) • Local • Rcs (Mac OS Developer Tools) • Centralized • Subversion • CVS • Perforce • Distributed • Git • Mercurial

Slide 5

Slide 5 text

Very good resource

Slide 6

Slide 6 text

Centralized CVS

Slide 7

Slide 7 text

Distributed CVS

Slide 8

Slide 8 text

Centralized • Pros • Looks simple • We know it well; we've been using it for a long time • Good mainstream IDEs integration • It works  • Cons • We cannot commit offline (well, we can, but …) • We cannot integrate in our development toolset more than one repository • Dificult to collaborate if team is large (i.e. open source projects) • We are encouraged to avoid branches by the system.

Slide 9

Slide 9 text

Distributed • Pros • Allow offline work • Easy collaboration model • Can link as many repositories as we might need • Almost every operation is local • Complete copy of the repository in each machine • Easy installation on server, and plenty of hosting services (free and paid) • Cons • More complex workflow (or not?) • Difficult to learn • ?????

Slide 10

Slide 10 text

Internal representation of data; SVN

Slide 11

Slide 11 text

Branching in SVN

Slide 12

Slide 12 text

Branching in SVN Quotes taken from official svn website • "For projects that have a large number of contributors, it's common for most people to have working copies of the trunk. Whenever someone needs to make a long-running change that is likely to disrupt the trunk, a standard procedure is to create a private branch and commit changes there until all the work is complete" • "The bad news is that it's very easy to drift too far apart (...) it may be near-impossible to merge your changes back into the trunk without a huge number of conflicts" • "Subversion gives you the ability to selectively “copy” changes between branches. And when you're completely finished with your branch, your entire set of branch changes can be copied back into the trunk. In Subversion terminology, the general act of replicating changes from one branch to another is called merging, and it is performed using various invocations of the svn merge subcommand”

Slide 13

Slide 13 text

Branching in SVN I (typical workflow) • Checkout from trunk. • Add a new file to working copy • Check status (svn st). • Track new file in svn (svn add). • Commit the new file (svn ci). • Modify the file, and check status again (svn st). • Commit the new change. • Modify again and let it remain modified.

Slide 14

Slide 14 text

Branching in SVN II (branch & merge) • Svn copy at server level. • Check current working copy remote path (svn info). • Switch to new location (svn switch [remote] .) • Check remote again (svn info). • Commit some change to the branch. • Switch again to trunk. • Merge trunk with [myNewBranch] (svn merge [source@rev] .). Note that we do it with the working copy first to merge conflicts locally. • Commit to finish merge (we’ve done it locally in the previous step). • Again with a non-conflicting change in the same file. • Again with a conflicting change.

Slide 15

Slide 15 text

Internal representation of data; svn • Repository: the main idea • Working copy • Revisions, which are deltas of a base state • The server has to workout deltas to resolve the concrete state of a revision (commit) • Each revision gets a unique (secuential) id. This is possible because it's centralized • Branches: are light copies of complete working trees • Summary: branch=copy.

Slide 16

Slide 16 text

Drawbacks I: only one remote

Slide 17

Slide 17 text

Drawbacks II: branch & merge sucks • Recall branch & merge procedure: • Copy trunk in branch directory in remote server • Checkout (or switch) locally. • Inspect revision we want to merge with, if not last. • Call svn merge. • Resolve conflicts (if any). • Commit the whole thing. • In practice we feel encouraged to not create branches (bad, bad, bad …).

Slide 18

Slide 18 text

Drawback III: cleanliness • What if I want to merge my branch just to get up to date with our trunk, but I don’t want to make it public yet (incomplete feature or just playing around)?

Slide 19

Slide 19 text

Drawback IV: privacy • Do I have to publish my code to a remote/public server to have version control? What if I’m doing some experiments I don’t want other people to see, or I just don’t want to mess up our central repository with something I don’t know if it’s going to work?

Slide 20

Slide 20 text

Internal representation of data; git

Slide 21

Slide 21 text

Git – file status lifecycle

Slide 22

Slide 22 text

Git internal storage structure: directed acyclic graph (DAG) • http://eagain.net/articles/git-for-computer-scientists/

Slide 23

Slide 23 text

Branching in git

Slide 24

Slide 24 text

Deeper insight in git DAG internal structure

Slide 25

Slide 25 text

Another view of git objects I

Slide 26

Slide 26 text

Another view of git objects II

Slide 27

Slide 27 text

Another view of git objects III

Slide 28

Slide 28 text

Details on how git stores that in disk • http://git-scm.com/book/en/Git-Internals-Git-Objects

Slide 29

Slide 29 text

Branches and HEAD

Slide 30

Slide 30 text

More on git internal representation of data • http://eagain.net/articles/git-for-computer-scientists/ • http://en.wikipedia.org/wiki/Directed_acyclic_graph • Due to its distributed nature unique ids for commits are generated as SHA-1 digest to ensure unicity • Explanation • Snapshots, not deltas • Commits: blobs • Branches: references to commits • Repeat: branch = pointer • Current branch: HEAD pointer • Detached heads: careful

Slide 31

Slide 31 text

SVN branch & merge summary • SVN has no branch concept. It's just another working copy with a common history • We can only merge two branches at a time • SVN allow you to merge even not at all related trees (error prone) • Refactor and moving things around; svn doesn't manage this kind of merges very well • Only allows interaction one repository at a time.

Slide 32

Slide 32 text

Git branch & merge summary • It’s trivial to create a new branch from any point. • Git prevents us from deleting unmerged branches. • We can clean up obsolete branches keeping commits. • We can move a branch around (recreate it from any starting point). • We can merge more than one branch at a time (3 or even more!!!). • Git understands moved and renamed files. • This model encourage best practices: branch-per-feature, local branches for testing and experiments, git-flow …

Slide 33

Slide 33 text

Git allow us to manage branching well

Slide 34

Slide 34 text

Git integration with SVN

Slide 35

Slide 35 text

Interesting git resource • http://git-scm.com • http://git-scm.com/docs/gittutorial • http://eagain.net/articles/git-for-computer-scientists/ • http://try.github.io/levels/1/challenges/1 • http://www.vogella.com/articles/Git/article.html • https://help.github.com/articles/ • http://gitimmersion.com

Slide 36

Slide 36 text

Wich CVS should I choose and when?