Nguyễn Vũ Hưng: Subversion best practices


Published on

Kinh nghiệm sử dụng subverision để quản lý thông tin, phiên bản của tệp, cũng như dự án (IT) nói chung

Published in: Technology
  • Chào Bạn

    Bên mình hiện cung cấp gói Hosting đã tích hợp sẵn SVN bạn nhé. Mình có các gói Hosting bình thường (có tích hợp - có thể test luôn) và gói chuyên dùng SVN (Không có MySQL - dung lượng ổ đĩa lớn hơn gói hosting bình thường.

    Các Bạn có nhu cầu sử dụng dịch vụ SVN thì liên hệ mình nhé

    Link bảng giá hosting SVN:
    Hướng dấn sử dụng SVN:

    Nguyễn Trung Văn
    Email: /
    YM: vannt_99 / Skype: vannt_99
    ĐT: 01656.95.86.88
    Are you sure you want to  Yes  No
    Your message goes here
  • Anh Hưng quảng bá cho cái mới là Git đi chứ :P
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Nguyễn Vũ Hưng: Subversion best practices

  1. 1. Version Control::Subversion Best Practices Nguyen Vu Hung 2012/04/11 vuhung16plus(at) 2010/10/05 Subversion 101 Nguyen Vu Hung
  2. 2. Change HistoryNo Author Date Slides Details1 Vuhung 2010/10/04 All Newly created2 Vuhung 2010/10/05 - -3 Vuhung 2011/01/06 All Remove private info4 Vuhung 2012/04/11 All Convert to odp, add svn tips2010/10/05 Subversion 101 Nguyen Vu Hung
  3. 3. AgendaIntroductionThe SymptomsRevision Control System overviewAtomic CommitsRevision ExplainedSvn HistoryOverviewBasic usagesArchitectureComponentsInstallationServer, client2010/10/05 Subversion 101 Nguyen Vu Hung
  4. 4. Agenda (2)IDE integrationCommand comparison TipsWorkflow Examing HistoryStaging Summary: Basic CommandsStaging (Debian) Summary: What svn can do?Repository schema Summary: TerminologiesResolve Conflicts AlternativesBasic Commands ReferencesMergingRevertUpdateAddDeletecopymovemkdirstatusdiff2010/10/05 Subversion 101 Nguyen Vu Hung
  5. 5. The SymptomsYou need files in Recycle BinHaving more than 2 levels of undo (backup) in adocumentvet_20100823.sql, vet_20100824.sql, vet_bak.sql,Asking someone to send a copy of some files.FTP transaction diedYou don’t know what is done yesterdayIt works yesterday, but not today.URGENT: roll backFailed to manage source code change/merging2010/10/05 Subversion 101 Nguyen Vu Hung
  6. 6. Revision Control SystemRevision control, also known as version control, source control or software configuration management (SCM), is the management of changes to documents, programs, and other information stored as computer files. It is most commonly used in software development, where a team of people may change the same files. Changes are usually identified by a number or letter code, termed the "revision number", "revision level", or simply "revision". For example, an initial set of files is "revision 1". When the first change is made, the resulting set is "revision 2", and so on. Each revision is associated with a timestamp and the person making the change. Revisions can be compared, restored, and with some types of files, merged.2010/10/05 Subversion 101 Nguyen Vu Hung
  7. 7. Atomic CommitsNone or entire 0 1 2Single OperationRevision:per-commitNo inconsistence in largecommitsFiles within a commit aregrouped 2010/10/05 Subversion 101 Nguyen Vu Hung
  8. 8. Revision Control system 0 1 2 3 As Atomic Changes Not just change, It is change management2010/10/05 Subversion 101 Nguyen Vu Hung
  9. 9. HistoryJune 2000 - Coding begins.August 2001 - Subversion becomes self-hosting.2002 – 1st release2004 – Feb. Release 1.0.02006 – Sept. Release 1.4.0Latest Release: 1.4.6 2010/10/05 Subversion 101 Nguyen Vu Hung
  10. 10. Usages Configuration Backing up data Management Documentation Distributed Development CR 122010/10/05 Subversion 101 Nguyen Vu Hung
  11. 11. Architecture Client Interface Repository Interface FSFS Apache mod_ dav GUI client Repository apps access mod_ dav_ svn DAV Client Internet Library (A TCP/ Network) ny IP SVN svnserve Com mandline client apps Subversion Local Repository Offline Support Working Copy Management Unix/Linux/Windows/Mac OS X Library WebDav Integration Berkley DB SSL LDAP2010/10/05 Subversion 101 Nguyen Vu Hung
  12. 12. Subversion Componentssvn (this is what you [client] need)The command-line client program.svnadmin A tool for creating, tweaking or repairing a Subversionrepository.svnserveA custom standalone server program, runnable as adaemon process or invokable by SSH; another way tomake your repository available to others over a network.2010/10/05 Subversion 101 Nguyen Vu Hung
  13. 13. Installation (server)yum install mod_dav_svn subversion2010/10/05 Subversion 101 Nguyen Vu Hung
  14. 14. Installation (server settings) [root@vinicorp conf]# cat /etc/httpd/conf.d/subversion.conf LoadModule dav_svn_module modules/ LoadModule authz_svn_module modules/ <Location /svn-repo> DAV svn SVNParentPath /svn-repo # Limit write permission to list of valid users. <LimitExcept GET PROPFIND OPTIONS REPORT> # Require SSL connection for password protection. # SSLRequireSSL AuthType Basic AuthName "Vinicorp Subversion Realm" AuthUserFile /etc/svn-auth-conf Require valid-user </LimitExcept>2010/10/05 Subversion 101 Nguyen Vu Hung
  15. 15. Installation (server settings) [root@vinicorp conf]# head /etc/svn-auth-conf #vinicorp:pIuFZUS0McheY hoatran:3cYHbUvT9aV0o doancuong:0K3C3IdVJD7VY thuanvd:xJSWLpXNr5/EM hiennb:GHvHoKOG2E1eI huyenvtt:FySHeMI9u9uvc trungdq:MB7kxm/IgGMsY thuytp:rw68sUTpnVD7M thangnv:zSoOwCSdqqcLk phuongdt:o2ZYftrCjq2oM [root@vinicorp conf]# wc -l /etc/svn-auth-conf 51 /etc/svn-auth-conf2010/10/05 Subversion 101 Nguyen Vu Hung
  16. 16. Installation (server settings) [root@conf]# head /etc/svn-auth-conf #xxxxxxxxxx:pIuFZUS0McheY xxxxxxxxxx:3cYHbUvT9aV0o xxxxxxxxxx:0K3C3IdVJD7VY xxxxxxxxxx:xJSWLpXNr5/EM xxxxxxxxxx:GHvHoKOG2E1eI Create a repo: xxxxxxxxxx:FySHeMI9u9uvc mkdir /svn-repo xxxxxxxxxx:MB7kxm/IgGMsY Create an user: xxxxxxxxxx:rw68sUTpnVD7M htpasswd -c /etc/svn-auth-conf <username> xxxxxxxxxx:zSoOwCSdqqcLk xxxxxxxxxx:o2ZYftrCjq2oM [root@conf]# wc -l /etc/svn-auth-conf 51 /etc/svn-auth-conf2010/10/05 Subversion 101 Nguyen Vu Hung
  17. 17. Installation (server settings) [root@ svn-repo]# pwd /svn-repo [root@ svn-repo]# ls -1 001.Project1 005. Project2 006. Project32010/10/05 Subversion 101 Nguyen Vu Hung
  18. 18. Installation (server settings) [root@ svn-repo]# pwd /svn-repo [root@ svn-repo]# ls -1 001.Project1 005.Project2 006.Project3cd /svn-reposvnadmin create 001.Project1chown -R apache.apache 001.Project1service httpd restart2010/10/05 Subversion 101 Nguyen Vu Hung
  19. 19. Installation (client)TortoiseSVN (Windows)svn/subversion (Unix/Linux)svn (Mac OS X)RapidSVN (cross-platform)2010/10/05 Subversion 101 Nguyen Vu Hung
  20. 20. IDE integrationsvn + Eclipse = Subclipsesvn + File Explorer = Tortoisvnsvn + GUI = Rapid svnsvn + vim = svnSvn + emacs = svn2010/10/05 Subversion 101 Nguyen Vu Hung
  21. 21. Command comparisonAvailable subcommands: add blame log(praise, annotate, ann) merge cat mkdir checkout (co) move cleanup (mv, rename, ren) commit (ci) propdel (pdel, pd) copy (cp) delete propedit (pedit, pe)(del, remove, rm) propget (pget, pg) diff (di) proplist (plist, pl) export propset (pset, ps) help (?, h) resolved import revert info list (ls) status (stat, st) lock switch (sw) unlock update (up) 2010/10/05 Subversion 101 Nguyen Vu Hung
  22. 22. Workflow (admin)Create a repository (once)Import or Checkout repository (once)Update and Check-inMergeCommit2010/10/05 Subversion 101 Nguyen Vu Hung
  23. 23. User WorkflowStep 1Obtain SVN Repository URL from SVN AdminEx 1: svn://192.168.x.3/svn-repo/0xx.ProjEx 2: http://192.168.x.3/svn-repo/0xx.ProjStep 2Checkout SVN module (Repository Copy) to local filesystem (Working Copy)Step 3Update, Commit, Branch, Tag etc...2010/10/05 Subversion 101 Nguyen Vu Hung
  24. 24. WorkflowUpdate your working copysvn updateMake changessvn addsvn deletesvn copysvn moveExamine your changessvn statussvn diffPossibly undo some changessvn revertResolve Conflicts (Merge Others Changes)svn updatesvn resolvedCommit your changessvn commit2010/10/05 Subversion 101 Nguyen Vu Hung
  25. 25. Work flow Submit your changes get content svn commit svn checkout svn update 106 100 Merge your changes Resolve conflicts Make changes svn diff Subversion svn resolved svn add Repository svn move svn delete 105 See what was changed Update your local copy in the repository in the meantime svn update svn status -u2010/10/05 Subversion 101 Nguyen Vu Hung
  26. 26. Branching Root Easy to understand Cheap (a little copy) PC Can be deleted/reanimated trunk branches PC branch (vuhung) iPhone trunk branches2010/10/05 Subversion 101 Nguyen Vu Hung
  27. 27. Branching (2) Root 001.SPS trunk branches HuyDN HungNT2010/10/05 Subversion 101 Nguyen Vu Hung
  28. 28. StagingStaging can be managed via folder structures Root Project 1 trunk tags Dev Development stage ( QA Releases for QA (Test [For the Customer]) Rel Final Releases ( Subversion 101 Nguyen Vu Hung
  29. 29. Real World Example: Debian2010/10/05 Subversion 101 Nguyen Vu Hung
  30. 30. Repository schema Schema and Access Methodfile:/// direct repository access (on local disk)http:/ access via WebDAV protocol to Subversion-aware Apache serverhttps:// same as http://, but with SSL encryption.svn:// access via custom protocol to an svnserve serversvn+ssh:// same as svn://, but through an SSH tunnel.2010/10/05 Subversion 101 Nguyen Vu Hung
  31. 31. Resolve ConflictsFor example, Sally makes changes to the file sandwich.txt in the repository.Harry has just changed the file in his working copy and checked it in. Sallyupdates her working copy before checking in and she gets a conflict:$ svn updateC sandwich.txtUpdated to revision 2.$ ls -1sandwich.txtsandwich.txt.minesandwich.txt.r1sandwich.txt.r2At this point, Subversion will not allow you to commit the file sandwich.txtuntil the three temporary files are removed.2010/10/05 Subversion 101 Nguyen Vu Hung
  32. 32. Resolove Conflicts$ svn commit -m "Add a few more things"svn: Commit failed (details follow):svn: Aborting commit: /home/vuhung/work/sandwich.txt remains in conflictIf you get a conflict, you need to do one of three things:Merge the conflicted text “by hand” (by examining and editing the conflict markers within thefile).Copy one of the temporary files on top of your working file.Run svn revert <filename> 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 astate of conflict.[6] $ svn resolved sandwich.txtResolved conflicted state of sandwich.txt2010/10/05 Subversion 101 Nguyen Vu Hung
  33. 33. MergeWe both update the same file at the sametime. What happens?Update tells me there is a conflictYou checked yours in firstI have to merge the two updates together.Before checking in2010/10/05 Subversion 101 Nguyen Vu Hung
  34. 34. Merge Conflicts by hand Merging conflicts byy, your collaborator, both edit the file sandwich.txt at the same time. Sally commits her changes, and when you go to update your workin hand can be quite intimidating the first time you attempt it, but with a little practice, it can become as easy as falling off a bike. 2010/10/05 Subversion 101 Nguyen Vu Hung
  35. 35. Merging: RevertPunting: Using svn revertIf you get a conflict, and upon examination decide that you want to throwout your changes and start your edits again, just revert your changes:$ svn revert sandwich.txtReverted sandwich.txt$ ls sandwich.*sandwich.txtNote that when you revert a conflicted file, you dont have to run svnresolved.2010/10/05 Subversion 101 Nguyen Vu Hung
  36. 36. CheckinCheck-in - Update the central repository tomatch your local filesAlways update before checking in (svnenforces this)Always test with the latest update beforechecking in (not enforced)2010/10/05 Subversion 101 Nguyen Vu Hung
  37. 37. commitsvn commit command sends all of yourchanges to the repository. When you commit achange, you need to supply a log message,describing your change. Your log message willbe attached to the new revision you create.Log message can be set in command line usingthe --message (or -m) switch: $ svn commit -m "Corrected number of cheese slices." Sending sandwich.txt Transmitting file data . Committed revision 3.2010/10/05 Subversion 101 Nguyen Vu Hung
  38. 38. checkout$ svn checkout http://192.168.x.3/svn-repo/0xx.ProjA 0xx.Proj/SourceCodeA 0xx.Proj/Document…Checked out revision 1. 2010/10/05 Subversion 101 Nguyen Vu Hung
  39. 39. updateUpdate - Updates the local files to match thecentral repositoryNOTE: Change to the working folder (the local folderthat you have checked out from the repository intoyour local file system) svn update U SourceCode/<moduleName>/public/images/basic_title_bg.gif U SourceCode/<moduleName>/public/images/btn_search.gif   Updated to revision 2.2010/10/05 Subversion 101 Nguyen Vu Hung
  40. 40. svn addsvn add fooSchedule file, directory, or symboliclink foo to be added to therepository. When you next commit, foowill become a child of its parentdirectory. Note that if foo is adirectory, everything underneath foowill be scheduled for addition. Ifyou only want to add foo itself, passthe --non-recursive (-N) option.2010/10/05 Subversion 101 Nguyen Vu Hung
  41. 41. svn deletesvn delete fooSchedule file, directory, or ymboliclink foo to be deleted from therepository. If foo is a file or link, itis immediately deleted from your workingcopy. If foo is a directory, it is notdeleted, but Subversion schedules it fordeletion. When you commit your changes,foo will be removed from your workingcopy and the repository. 2010/10/05 Subversion 101 Nguyen Vu Hung
  42. 42. svn copysvn copy foo barCreate a new item bar as a duplicateof foo and automatically schedule barfor addition. When bar is added to therepository on the next commit, itscopy history is recorded (as havingoriginally come from foo). svn copydoes not create intermediatedirectories.2010/10/05 Subversion 101 Nguyen Vu Hung
  43. 43. svn movesvn move foo barThis command is exactly the same asrunning svn copy foo bar; svn delete foo.That is, bar is scheduled for addition asa copy of foo, and foo is scheduled forremoval. svn move does not createintermediate directories. 2010/10/05 Subversion 101 Nguyen Vu Hung
  44. 44. svn mkdirsvn mkdir blortThis command is exactly the same asrunning mkdir blort; svn add blort.That is, a new directory named blortis created and scheduled foraddition.2010/10/05 Subversion 101 Nguyen Vu Hung
  45. 45. svn update (2)Update working copyUpdate all files and directories to the most current version $svn updateGo to a particular older revision for all files and directories $% svn update –r 1345I want an even older version of svn-doc.el $% svn update –r 999 FolderNameUpdate output and what it meansU `fooFile `foo was (U)pdated (received changes from the server.)A `fooFile or directory `foo was (A)dded to your working copy.D `fooFile or directory `foo was (D)eleted from your working copy.R `fooFile or directory `foo was (R)eplaced in your working copy; that is, `foo was deleted, and a new item with the same name was added. While they mayhave the same name, the repository considers them to be distinct objects with distinct histories.G `fooFile `foo received new changes, but also had changes of your own to begin with. The changes did not intersect, however, so Subversion has mer(G)edthe repositorys changes into the file without a problem.C `fooFile `foo received (C)onflicting changes from the server. The changes from the server directly overlap your own changes to the file. No need to panic,though. This overlap needs to be resolved by a human (you).2010/10/05 Subversion 101 Nguyen Vu Hung
  46. 46. svn status svn status A Daily/20100927/chuyen.txt # file is scheduled for addition C Daily/20100824/iPadQA.xl # file has textual conflicts from an update D Daily/20100927/chuyen.lrc # file is scheduled for deletion M Daily/20100927 # the content in Daily/20100927 has local modifications A item The file, directory, or symbolic link item has been scheduled for addition into the repository. C item The file item is in a state of conflict. That is, changes received from the server during an update overlap with local changes that you have in your working copy. You must resolve this conflict before committing your changes to the repository. D item The file, directory, or symbolic link item has been scheduled for deletion from the repository. M item The contents of the file item have been modified.2010/10/05 Subversion 101 Nguyen Vu Hung
  47. 47. Svn diff [vuhung@ 20100927]$ svn diff . Index: chuyen.lrc =================================================================== --- chuyen.lrc (revision 166) +++ chuyen.lrc (working copy) @@ -5,15 +5,15 @@ [00:15.83]chieu ngoai o, gio khe dua toc em [00:26.51]Cong cong con duong uon quanh. -[00:30.71]chieu dao pho, chieu mang chut huong thanh binh [00:46.72]Thuong anh yeu anh em uoc mo. -[01:01.23]Uoc mo nho be trong doi +[01:01.23]Uoc va mo nho be trong doi [01:16.11]UOc mo cho tinh yeu len hat sac xuan +[01:16.11]UOc mo cho tinh yeu len hat sac xuan [01:21.19]Uoc mo la la tren canh [01:27.07]Nguoc mat thay bao giac mo. @@ -44,4 +44,4 @@ [03:53.07]??c m? nh? be trong ??i [03:58.84]Ng??c m?t th?y bao gi?c m?. -[04:10:10] No newline at end of file +[04:10:10]2010/10/05 Subversion 101 Nguyen Vu Hung
  48. 48. TipsCommit smallCommit oftenComment, comment, commentChange setsvn update (online) vs. svn status (offline)svn log: who && whatsvn merge = you + me.svn update and test before commitWork on local copySolve the conflictsDo not commit hidden, un-related, temporary files.2010/10/05 Subversion 101 Nguyen Vu Hung
  49. 49. Examining Historysvn logsvn diffsvn historysvn list2010/10/05 Subversion 101 Nguyen Vu Hung
  50. 50. Summary: Basic Commandssvn add — Add files, directories, or symbolic links.svn copy — Copy a file or directory in a working copy or in the repository.svn mkdir — Create a new directory under version control.svn delete — Delete an item from a working copy or the repository.svn export — Export a clean directory tree.svn import — Commit an unversioned file or tree into the repository.svn move — Move a file or directorysvn diff — Display the differences between two paths.svn merge — Apply the differences between two sources to a working copy path.svn resolved — Remove “conflicted” state on working copy files or directories.svn revert — Undo all local edits.svn status — Print the status of working copy files and directories.svn update — Update your working copy.svn checkout — Check out a working copy from a repository.svn commit — Send changes from your working copy to the repository.2010/10/05 Subversion 101 Nguyen Vu Hung
  51. 51. Summary: What svn can do?Backup and Restore. Files are saved as they are edited, and you can jump to anymoment in time. Need that file as it was on Feb 23, 2007? No problem.Synchronization. Lets people share files and stay up-to-date with the latestversion.Short-term undo. Monkeying with a file and messed it up? (That’s just like you,isn’t it?). Throw away your changes and go back to the “last known good” version inthe database.Long-term undo. Sometimes we mess up bad. Suppose you made a change a yearago, and it had a bug. Jump back to the old version, and see what change was madethat day.Track Changes. As files are updated, you can leave messages explaining why thechange happened (stored in the VCS, not the file). This makes it easy to see how afile is evolving over time, and why.Track Ownership. A VCS tags every change with the name of the person whomade it. Helpful for blamestorming giving credit.Sandboxing, or insurance against yourself. Making a big change? You can maketemporary changes in an isolated area, test and work out the kinks before“checking in” your changes.Branching and merging. A larger sandbox. You can branch a copy of your codeinto a separate area and modify it in isolation (tracking changes separately). Later,you can merge your work back into the common area.2010/10/05 Subversion 101 Nguyen Vu Hung
  52. 52. Summary: Terminologies (Basic Setup)Repository (repo): The database storing thefiles.Server: The computer storing the repo.Client: The computer connecting to the repo.Working Set/Working Copy: Your localdirectory of files, where you make changes.Trunk/Main: The primary location for code inthe repo. Think of code as a family tree — thetrunk is the main line.2010/10/05 Subversion 101 Nguyen Vu Hung
  53. 53. Summary: Terminologies (Basic Actions )Add: Put a file into the repo for the first time, i.e. begin tracking it withVersion Control.Revision: What version a file is on (v1, v2, v3, etc.).Head: The latest revision in the repo.Check out: Download a file from the repo.Check in: Upload a file to the repository (if it has changed). The file gets anew revision number, and people can “check out” the latest one.Checkin Message: A short message describing what was changed.Changelog/History: A list of changes made to a file since it was created.Update/Sync: Synchronize your files with the latest from the repository.This lets you grab the latest revisions of all files.Revert: Throw away your local changes and reload the latest version fromthe repository.2010/10/05 Subversion 101 Nguyen Vu Hung
  54. 54. Summary: Terminologies (Advanced Actions)Branch: Create a separate copy of a file/folder for private use (bug fixing, testing,etc). Branch is both a verb (”branch the code”) and a noun (”Which branch is itin?”).Diff/Change/Delta: Finding the differences between two files. Useful for seeingwhat changed between revisions.Merge (or patch): Apply the changes from one file to another, to bring it up-to-date.For example, you can merge features from one branch into another. (At Microsoftthis was called Reverse Integrate and Forward Integrate)Conflict: When pending changes to a file contradict each other (both changescannot be applied).Resolve: Fixing the changes that contradict each other and checking in the correctversion.Locking: Taking control of a file so nobody else can edit it until you unlock it. Someversion control systems use this to avoid conflicts.Breaking the lock: Forcibly unlocking a file so you can edit it. It may be needed ifsomeone locks a file and goes on vacation (or “calls in sick” the day Halo 3 comesout).Check out for edit: Checking out an “editable” version of a file. Some VCSes haveeditable files by default, others require an explicit command.2010/10/05 Subversion 101 Nguyen Vu Hung
  55. 55. AlternativesHistoricalRCS (Revision Control System)Distributed modelBazzar (python-based, Canonical supported)Git (Perl, C, shell based)Open sourceCVS (Concurrent Versions System)CSVNT (for Windows [NT])ProprietaryCMVC (Configuration Management Version Control) (IBM)Visual Source Safe (Microsoft)Visual Studio Team System (Microsoft)2010/10/05 Subversion 101 Nguyen Vu Hung
  56. 56. 2010/10/05 Subversion 101 Nguyen Vu Hung
  57. 57. ReferencesPolarion subversion tutorial jscreationzs Subversion 101 Nguyen Vu Hung
  58. 58. Version Control::Subversion Best Practices Nguyen Vu Hung 2012/04/11 vuhung16plus(at) 2010/10/05 Subversion 101 Nguyen Vu Hung