33
Version Control with CVS Peter Dinda Department of Computer Science Northwestern University

Version Control with CVS

Embed Size (px)

DESCRIPTION

Version Control with CVS. Peter Dinda Department of Computer Science Northwestern University. What is Version Control?. Go back in time Undo nasty mistakes by you or others Coordinate among multiple developers Avoid stepping on each others toes Also for working on multiple machines - PowerPoint PPT Presentation

Citation preview

Page 1: Version Control with CVS

Version Controlwith CVS

Peter Dinda

Department of Computer Science

Northwestern University

Page 2: Version Control with CVS

What is Version Control?

• Go back in time– Undo nasty mistakes by you or others

• Coordinate among multiple developers– Avoid stepping on each others toes– Also for working on multiple machines

• Me: desktop, laptop, home machine

• Collective model of the “project”– Including multiple variants

Page 3: Version Control with CVS

What does it look like?

Alice’s Local Version Joe’s Local Version Jane’s Local Version

All Versions of all the filesThe “Repository”

Page 4: Version Control with CVS

What does it look like?

Alice’s Local Version Joe’s Local Version Jane’s Local Version

All Versions of all the filesThe “Repository”

Add a new file(or directory)that everyonecan see

“OK” or “File already exists”

Page 5: Version Control with CVS

What does it look like?

Alice’s Local Version Joe’s Local Version Jane’s Local Version

All Versions of all the filesThe “Repository”

Commit mychanges so everyone can see them

“OK” or “Your files are out of date”

Page 6: Version Control with CVS

What does it look like?

Alice’s Local Version Joe’s Local Version Jane’s Local Version

All Versions of all the filesThe “Repository”

Update my local filesto reflect all changes“OK” or

“Your files conflict”

Page 7: Version Control with CVS

What does it look like?

Alice’s Local Version Joe’s Local Version Jane’s Local Version

All Versions of all the filesThe “Repository”

Call what I have“Release 1.0”

“OK”

Page 8: Version Control with CVS

What does it look like?

Alice’s Local Version Joe’s Local Version Jane’s Local Version

All Versions of all the filesThe “Repository”

Create a separateversion: “Release 1.0.joe” for local testing

“OK”

Page 9: Version Control with CVS

What does it look like?

Alice’s Local Version Joe’s Local Version Jane’s Local Version

All Versions of all the filesThe “Repository”

“OK”

Six Months Later

Merge my special versionback into themain product

Page 10: Version Control with CVS

What does it look like?

Alice’s Local Version Joe’s Local Version Jane’s Local Version

All Versions of all the filesThe “Repository”

Give me “Release 1.0”

“OK”

One Year Later

Release 1.5-Joe causes injuries!

Page 11: Version Control with CVS

How do I get it?

• CVS– Free, works on Windows, Linux, Unix, etc.– Used a LOT, but has assorted cruft

• Subversion– Free, works on Windows, Linux, Unix, etc.– “A better CVS” – same commands, uses our old

friend, Mr. Transaction, on top of BerkeleyDB• Others (pay)

– Visual Source Safe (MS)– Perforce (very highly regarded)– Generally pay to get better branching support

Page 12: Version Control with CVS

CVS The Easy Way

• Linux or Unix box– Probably already installed. Run “cvs”.– export EDITOR=“xemacs –nw”

• Default EDITOR is typically vi

• Windows box– Just install cygwin – it will just work– Various command-line and GUI-based cvs

clients are also available

Page 13: Version Control with CVS

Do I need a special server?

• No. You just need a directory that’s accessible by all the developers.

• export CVSROOT=/home/pdinda/MYCVS

• No. Even if you want to use a remote machine, just use ssh:

• export CVS_RSH=ssh• export CVSROOT=

:ext:pdinda@tlab-login:/home/pdinda/MYCVS

• No. Even if you have multiple developers, just use Unix groups and the group sticky bit

• chown pdinda.mycvsgroup /home/pdinda/MYCVS• chmod g+s /home/pdinda/MYCVS

• No. Don’t bother with “pserver” and “kserver” unless you need them.

• You almost certainly do not

Page 14: Version Control with CVS

Getting CVS Help

• cvs –help-commands– Does what you might expect

• cvs –H command– Tells you the details of the command

• There are lots of CVS commands. You only need to use a few: init, import, add, remove, checkout, commit, update, tag

Page 15: Version Control with CVS

Initializing the Repository

• Only done once

• cvs init

• Creates directory and initial files

Page 16: Version Control with CVS

Bringing a directory (module) into CVS

• cd btree_lab• cvs import my_btree_lab PDINDA PDINDA0

– my_btree_lab – what I’m going to call it– PDINDA – my “Vendor tag”– PDINDA0 – my “Vendor release tag”

• IMPORTANT: btree_lab is *NOT* under the control of CVS. We must check out my_btree_lab first!

Page 17: Version Control with CVS

Checking Out a Module

• cvs checkout my_btree_lab

• cd my_btree_lab

• (start working)

Page 18: Version Control with CVS

How do I add files and directories?

• cvs add filesanddirectories

• cvs add –kb file– the file is binary– Most clients figure this out themselves, but it’s

a good habit to have

Page 19: Version Control with CVS

How do I remove files and directories?

• cvs remove fileordirectory– “I don’t want cvs to manage this any more”

• cvs remove –f fileordirectory– “Not only should it not manage it, but delete

my local copy too.”

• Note that remove and add affect the REPOSITORY.

• Recovery: The “Attic”

Page 20: Version Control with CVS

How do I commit?

• cvs commit [files]

• You may get “up to date check failed for..”– This means you need to update those files first and fix

any conflicts before you can commit.

• Note that add/remove/edits/etc DO NOT GET REFLECTED IN THE REPOSITORY UNTIL YOUR COMMIT IS SUCCESSFUL

Page 21: Version Control with CVS

Getting Updates From The Repository

• cvs update [-d] [files]– -d => Get new subdirectories!– if files are not specified, everything in this

directory and its subdirectories is updated

Page 22: Version Control with CVS

Understanding Updates

• An update MERGES the version of the file that’s in the repository into the one on your disk– You have A– Repository has B– After update, you have MERGE(A,B)

• Merges are not always possible automatically. – CVS punts to you if this happens, reporting a conflict – You have to resolve the conflict yourself– This is uncommon in most development because

different developers are working on different files

Page 23: Version Control with CVS

What Versions do I have?

• cvs status [files]

• Each file and directory has a version number. – 1.1, 1.2, … (first level)– 1.1.1.1, 1.1.1.2, … (one level branch)

Page 24: Version Control with CVS

What are all the versions?

• cvs log file

• cvs rlog module (directory)

Page 25: Version Control with CVS

How can I give versions names?

• Current version:– cvs tag name files– cvs rtag name module

• Other versions:– cvs tag –r version …– cvs rtag similar

Page 26: Version Control with CVS

How do I go back in time?

• cvs update –r version file

• cvs update –r tag file

• cvs update –D datetime file

• This makes the file “sticky”, meaning that subsequent updates will not move it to a newer version

• You can update out of the sticky version by using cvs update –A

Page 27: Version Control with CVS

Branching

• So far, we’ve treated each file/directory as having a sequence of versions (1.1, 1.2, etc)

• CVS lets you have parallel versions, turning the version “linked list” into a version “tree”.

• In theory, very useful for when one wants to take a large project and create a “side project” without affecting the main line of development

Page 28: Version Control with CVS

Merging

• Versions are actually DAGs. You can take your “side project” version and merge it back into the mainline of development.

• This all sounds awesome, but…

Page 29: Version Control with CVS

Branching/Merging has Problems

• Branching is easy, but merging is hard• CVS basically gets this wrong• And the problem is compounded because IT DOES NOT

USE TRANSACTIONS FOR ANYTHING• It also doesn’t really provide any tools for dealing with

merge conflicts.

• So, a merge can end up half done! Blam: your project is in big trouble.

• Lack of transactions also bites you for updates and commits.

Page 30: Version Control with CVS

CVS Branch/Merge Advice

• Don’t use it.• Don’t use it.• Don’t use it.

• If you MUST use it, spend a lot of time making sure you understand it first.

• Buy a tool that supports this well^Wbetter if you need it.

Page 31: Version Control with CVS

Stupid Windows/Unix Issues

• Windows ends lines with \r\n– Sometimes likes to use Unicode too

• Unix ends lines in \n– And uses ASCII pretty much all the time

• CVS is line-oriented• End result: be very careful in setting up

your client on the foreign platform. Lots of web help on this, however.

Page 32: Version Control with CVS

Subversion

• An attempt to build a tool that has CVS’s command set but does not suffer from its problems– “svn” is the command– Big one: Transactions used throughout– Assorted bugs/misfeatures of CVS fixed in a way that

is sensible

• Looks pretty good. We’re using it for developing a class.

• But I’m pretty happy with CVS too

Page 33: Version Control with CVS

For More Info / Downloads

• CVS: http://www.cvshome.org/

• Subversion: http://subversion.tigris.org/ – Free Book: http://svnbook.red-bean.com/

• Perforce: http://www.perforce.com/

• VSS: http://www.microsoft.com