Anda di halaman 1dari 11

21 SVN commands every serious developer should know. I am trying to post some parts of that session over here.

Hope that it will be useful for that guys who are working on Open Source. 1. Help: Before reading on, here is the most important command youll ever need when using Subversion: svn help. The Subversion command-line client is self-documentingat any time,. $svn help Will display all available subcommands in svn. A quick svn help SUBCOMMAND will describe the syntax, switches, and behavior of the subcommand: $svn help checkout 2. checkout: Check out a working copy from a repository. Syntax: $svn checkout URL [PATH] ex: This copy contains the HEAD (latest revision) of the Subversion repository that you specify on the command line. $ svn checkout http://openappdotorg.googlecode.com/svn/trunk/ Although the above example checks out the trunk directory, you can just as easily check out any deep subdirectory of a repository by specifying the subdirectory in the checkout URL: $svn checkout http://openappdotorg.googlecode.com/svn/trunk/tests/ To checkout a specific revision: $svn checkout -r 8810 http://openappdotorg.googlecode.com/svn/trunk/ If you have username and password in repository then $svn checkout http://openappdotorg.googlecode.com/svn/trunk/ username <USER> password <PASSWORD>

3. update: Your Working Copy $ svn update If no revision given, bring working copy up-to-date with HEAD rev. Else synchronize working copy to revision given by -r. For each updated item a line will start with a character reporting the action taken. These characters have the following meaning: A Added D Deleted U Updated C Conflict G Merged 4. status: See an overview of your changes: $ svn status If you run svn status at the top of your working copy with no arguments, it will detect all file and tree changes youve made. Most common status codes that svn status can return: ## no modifications A mydir/foo.h ## file is scheduled for addition, this is new file, not in the repos C mydir/test/bar.c ## file has conflicts from an update D mydir/fish.c ## file is scheduled for deletion M bar.c ## the content in bar.c has local modifications ? foo.h ## item is not under version control ! bar.h ## item is missing (removed by non-svn command) or incomplete 5. diff: To see details of your local modifications: $ svn diff Output is displayed in unified diff format. That is, removed lines are prefaced with a and added lines are prefaced with a +

6. revert: Undoing Working Changes $ svn revert bar.c Subversion reverts the file to its pre-modified state by overwriting it with the cached copy from the .svn folder. By mistake you removed a file from version control: $ svn status bar.c bar.c $ svn delete bar.c D bar.c ## D: status code for delete $ svn revert bar.c Reverted bar.c $ svn status bar.c bar.c 7. resolved: Resolving Conflicts: Conflicts come when there is some changes at the same line in the working copy and copy from repository. We can predict conflict in files without updating it, just by using status command with -u switch $svn status -u $ svn update C bar.h This means that the changes from the repository overlapped with your own. Status code C during the update means that the file is in a state of conflict. For every conflicted file, Subversion places three extra unversioned files in your working copy bar.h.mine ##This is your file as it existed in your working copy before you updated your working ##copy; ie, without conflict markers bar.h.rOld ##This is the file that was the BASE revision before you updated your working copy. bar.h.rNew ##Latest revision in the repository.

Example of conflicted file: $ cat bar.h India SriLanka <<<<<<< .mine USA Canada ======= UK France >>>>>>> .rN Egypt South Africa The strings of <<<, ===, and >>> signs are conflict markers. You want to ensure that those are removed from the file before your next commit. The text between the first two sets of markers is composed of the changes you made in the conflicting area: <<<<<<< .mine USA Canada ======= The text between the second and third sets of markers is the text from others commit: ======= UK France >>>>>>> .rN Now you have to resolve the conflicts by: Merge the conflicted text by hand. Or remove your local changes by running:

$ svn revert bar.h // to throw away all of your local changes. Once youve resolved the conflict, you need to let Subversion know by running svn resolved. This removes the three temporary files and Subversion no longer considers the file to be in a state of conflict. $ svn resolved bar.h 8. commit: Send changes from your working copy to the repository. Syntax: $svn commit [PATH...] A log message must be provided, but it can be empty. If it is not given by a message or file option, an editor will be started. ex: $ svn commit -m included header file. bar.h 9. list: List directory entries in the repository. Syntax: $ svn list Target List each TARGET file and the contents of each TARGET directory as they exist in the repository. If TARGET is a working copy path, the corresponding repository URL will be used. The default TARGET is ., meaning the repository URL of the current working directory. svn list is most useful if you want to see what files a repository has without downloading a working copy: $ svn list http://openappdotorg.googlecode.com/svn/trunk/ 10. add: Add files, directories, or symbolic links to your working copy and schedule them for addition to the repository. They will be uploaded and added to the repository on your next commit. If you add something and change your mind before committing, you can unschedule the addition using svn revert.

Syntax: $svn add PATH ex: To add a file to working copy: $ svn add foo.txt A foo.txt ## A: status code Added When adding a directory, the default behavior of svn add is to recurse: $ svn add MyDir A MyDir A MyDir/a A MyDir/b 11. lock: Lock working copy paths or URLs in the repository, so that no other user can commit changes to them. Syntax: svn lock TARGET ex: Lock two files in your working copy: $ svn lock config.php config.png config.php locked by user sanjay. config.png locked by user sanjay. Lock a file in repository: $ svn lock http://openappdotorg.googlecode.com/svn/trunk/config.php config.php locked by user sanjay. 12. log: Display commit log messages. Syntax: svn log URL [PATH...] The default target is the path of your current directory. If no arguments are supplied, svn log

shows the log messages for all files and directories inside of (and including) the current working directory of your working copy. ex: You can see the log messages for all the paths that changed in your working copy by running svn log from the top: $svn log All log messages for a particular file in your working copy: $ svn log foo.h Log for a particular revision(20): $svn log -r 20 foo.h Log for range of revisions(from 20 to 25) $svn log -r 20:25 foo.h 13. unlock: Unlock working copy paths or URLs. Syntax: svn unlock TARGET ex: Unlock two files in your working copy: $ svn unlock config.php config.png config.php unlocked. config.png unlocked. Unlock a file in repository: $ svn unlock http://openappdotorg.googlecode.com/svn/trunk/config.php config.php unlocked 14. delete: Delete an item from a working copy or the repository. Syntax:

svn delete PATH svn delete URL ex: Using svn to delete a file from your working copy only schedules it to be deleted. When you commit, the file is deleted in the repository. $ svn delete myfile D myfile $ svn commit -m Deleted file myfile. Deleting myfile Transmitting file data . Committed revision 22. Deleting a URL, however, is immediate, so you have to supply a log message: $ svn delete -m Deleting file myfile http://openappdotorg.googlecode.com/svn/trunk/config.php Committed revision 25. 15. import: Commit an unversioned file or tree into the repository Syntax: svn import [PATH] URL Recursively commit a copy of PATH to URL. If PATH is omitted . is assumed. Parent directories are created in the repository as necessary. ex: This imports the local directory myproj into the root of your repository: $ svn import -m New import myproj http://openappdotorg.googlecode.com/svn/trunk 16. export: Export a clean directory tree. Syntax:

svn export [-r REV] URL [PATH] svn export [-r REV] PATH1 [PATH2] The first form exports a clean directory tree from the repository specified by URL, at revision REV if it is given, otherwise at HEAD, into PATH. If PATH is omitted, the last component of the URL is used for the local directory name. The second form exports a clean directory tree from the working copy specified by PATH1 into PATH2. All local changes will be preserved, but files not under version control will not be copied. ex: Export directly from the repository: $ svn export http://openappdotorg.googlecode.com/svn/trunk myApp 17. cat: Output the contents of the specified files or URLs. Syntax: svn cat TARGET ex: If you want to view config.txt in your repository without checking it out: $ svn cat http://openappdotorg.googlecode.com/svn/trunk/config.txt 18. mkdir: Create a new directory under version control. Syntax: svn mkdir PATH svn mkdir URL Create a directory with a name given by the final component of the PATH or URL. A directory specified by a working copy PATH is scheduled for addition in the working copy. A directory specified by a URL is created in the repository via an immediate commit. ex: Create a directory in your working copy:

$ svn mkdir newdir A newdir Create one in the repository (instant commit, so a log message is required): $ svn mkdir -m Making a new dir. http://openappdotorg.googlecode.com/svn/trunk/newdir 19. move: Move a file or directory. Syntax: svn move SOURCE DEST This command moves a file or directory in your working copy or in the repository. This command is equivalent to an svn copy followed by svn delete. ex: Move a file in your working copy: $ svn move foo.c bar.c A bar.c ##added D foo.c ##deleted Move a file in the repository (an immediate commit, so it requires a commit message): $ svn move -m Move a file http://openappdotorg.googlecode.com/svn/trunk/foo.c http://openappdotorg.googlecode.com/svn/trunk/bar.c 20. blame: Show author and revision information in-line for the specified files or URLs. Syntax: svn blame TARGET[@REV] Show author and revision information in-line for the specified files or URLs. Each line of text is annotated at the beginning with the author (username) and the revision number for the last change to that line

ex: $ svn blame http://openappdotorg.googlecode.com/svn/trunk/foo.c 21. copy: Copy a file or directory in a working copy or in the repository. Syntax: svn copy SOURCE DEST Copy a file in a working copy or in the repository. SOURCE and DEST can each be either a working copy path or URL. ex: Copy an item within your working copy (just schedules the copynothing goes into the repository until you commit): $ svn copy foo.txt bar.txt A bar.txt Copy an item in your working copy to a URL in the repository (an immediate commit, so you must supply a commit message): $ svn copy my.txt http://openappdotorg.googlecode.com/svn/trunk/my.txt -m Remote copy. Copy an item from the repository to your working copy (just schedules the copynothing goes into the repository until you commit): (This is the recommended way to resurrect a dead file in your repository) $ svn copy http://openappdotorg.googlecode.com/svn/trunk/my.txt A my.txt ##A: added

Anda mungkin juga menyukai