0000000000000000000000000
Total Page:16
File Type:pdf, Size:1020Kb
Why use version control? Setting up CVS Saves all previous versions of all files so that Create the repository: you can undo (buggy) edits. % mkdir ~/cvsroot % [set permissions for ~/cvsroot] % setenv CVSROOT ~/cvsroot Logs changes to files so you can trace how % cvs init your sources have evolved over time. Set the CVSROOT environment variable in Mediates conflicting changes made by your .cshrc file. several different users---helps keep consistency. Repository Creating a Project Project 1 Project 2 Project 3 Create a project from existing files: % cd base64 % cvs import -m “base64” base64 carlk start Checkout the new project and delete the old files. % cvs checkout base64 Working copies Development Process with CVS Dealing with Conflicts If another user has committed changes to Get working copy Get any changes cvs checkout cvs update lines you have edited, CVS will report a conflict. Your version Edit files decode (infile, stdout); <<<<<<< decode64.c if( fclose (infile) ) return 0; ======= cvs commit if( fclose (infile) ) printf(" couldn't close file."); >>>>>>> 1.5 no Repository version Conflicts? Manually edit to remove the conflict. yes cvs update Edits on different lines are automatically Most of the merged. Resolve time you stay conflicts in shaded loop. 1 Frequently Used Commands Keywords Get the latest revisions of files with: Useful to put dynamic information in source file. % cvs update When you get a new revision, keywords are replaced with information about the file. Write changes back to repository with: % cvs commit -m“log msg” Keyword Replaced with $Author$ Username who checked in this revision. If you omit –m the editor given in the EDITOR $Date$ Date the this revision was checked in. environment variable will be started. $Id$ A string containing the filename, revision, author, date, and some status info. Useful Add files to project with: at tops of files. % cvs add -m“log msg” files… $Revision$ The revision number of this file. Use -kb for binary files. $Log$ The complete history of this file. Remove files from project with: /* $Id$ * Author: $Author$ % rm file.c * $Log$ % cvs remove -m“log msg” file.c */ /* $Id: decode64.c,v 1.2 2001/04/01 17:32:45 carlk Exp $ * Author: $Author: carlk $ Most commands default to work on the current * $Log: decode64.c,v $ * Revision 1.2 2001/04/01 17:32:45 carlk directory and all its subdirectories. * added keywords */ Tracking Changes Tracking Repository History View history of commits: 1.1 diffs1.2 diffs 1.3 % cvs history –c Can view other events: % cvs history –x event_codes CVS keeps track of all revisions of your files. Code Event O Checkout command issued. View changes between two revisions: C Conflict detected. % cvs diff -r 1.2 -r 1.3 file G Merging was necessary (but no conflicts). % cvs –D “Apr 2” –D “Apr 3” file U A working file was copied from the repository. A A file was added. View the log comments: M A file was modified. % cvs log file R A file was removed. View when each line changed: e.g. % cvs annotate file % cvs history –x AR main.c 2 Getting Previous Versions Tags Tags associate a name with a set of particular Retrieve a given revision with: revisions of some files. Useful to mark a “release.” % cvs update -r 1.1 files… % cvs update –D “Apr 2” files… Create a new tag with: % cvs tag mytag main.c encode.c … Date can be in just about any reasonable format. Checkout a set of tagged files with: % cvs checkout -r mytag All subsequent updates will get given tag revision. 1.1 1.2 1.3 main.c 1.3 Start getting the most recent version: encode.c % cvs update -A files… 1.2 decode.c Remembering version numbers and dates can be 1.1 utils.c hard; use symbolic tags (next slide). Time Commit point Ignoring Files Running Scripts on Events Can force CVS to run shell scripts on events Many types of files should not go into the like commit. repository (*.bak, *.o, core) --- CVS ignores cvsroot/CVSROOT most of these. contains a file called commitinfo with lines of the following format: Can make CVS ignore any file by putting base64.* myshellscript file patterns into ~/.cvsignore.Eg. Regexp Shell script to matching run. encode64 directory name. decode64 *.gif If regexp matches the directory of a committed file, myshellscript will be run. CVS won’t include matching files in any Regexp can also be ALL or DEFAULT. commit or update operation. If myshellscript exits with non-zero status, It won’t generate warning messages if these commit will not be allowed. files are not in the repository. Similar mechanisms for other events. 3 CVS Over the Network CVS On Other Platforms CVS home page has clients for Windows XX, Repository Client Linux, and other Unix flavors. Computer ssh/rsh Computer (e.g. hats) http://www.cvshome.org/ No server process required. On other platforms, setup and use is similar, Uses ssh/rsh to communicate. On client: but exact syntax may differ. CVS home page also has excellent manual. % setenv CVS_RSH ssh Setup ssh so that it doesn’t ask for a password. SourceForge hosts open source projects for 1. generate keys with no password free. They provide: 2. put the public key file on server, add to CVS repositories authorization file. web servers 3. add hostname username to .shosts. compile farm and more… Client sets CVSROOT to: http://sourceforge.net/ :ext:[email protected]:dir/cvsroot CVS Quick Reference File Manipulation add Add a file or directory to be managed by CVS. % cvs add -m “new feature” mult.c remove Mark a file deleted in the repository; all previous versions will still be available. You should remove the working copy before issuing the this command. %rmmult.c % cvs remove -m “deleted feature” mult.c update Copy the most recent versions of the given files into the working directory. File defaults to “.”. commit Merge any changes made back into the repository. % cvs commit -m “fixed bug” mult.c tag Create a tag or a branch. File Information status Show information about files. Use -v to see what tags are attached to the files. diff Show the changes made between any two versions of a file. Defaults to showing the changes between working copy and most recent version. log Show the historyof given files. Setup init Create a new repository (probably only need to do this once). % cvs init -d ~/cvsroot import Create a new project from existing sources (in current directory). % cvs import -m “prj” prjname vendtag reltag Most commands take -m to specify a log message and -r to operate on a given revision/tag. 4.