首页 > > > 程序员修炼三部曲.版本控制之道.Pragmatic Version Control Using…

程序员修炼三部曲.版本控制之道.Pragmatic Version Control Using Subversion.pdf

程序员修炼三部曲.版本控制之道.Pragmatic Versi…

上传者: Jason 2012-01-05 评分1 评论0 下载640 收藏10 阅读量892 暂无简介 简介 举报

简介:本文档为《程序员修炼三部曲.版本控制之道.Pragmatic Version Control Using Subversionpdf》,可适用于IT书籍领域,主题内容包含WhatreadersaresayingaboutPragmaticVersionControlusingSubversionIexpectedal符等。

What readers are saying about Pragmatic Version Control using Subversion I expected a lot, but you surprised me with even more. Hav- ing used CVS for years I hesitated to try Subversion until now, although I knew it would solve many of the shortcom- ings of CVS. After reading your book, my excuses to stay with CVS disappeared. Oh, and coming from the Pragmatic Bookshelf this book is fun to read too. Thanks Mike. Steffen Gemkow Managing Director, ObjectFab GmbH I’m a long-time user of CVS and I’ve been skeptical of Sub- version, wondering if it would ever be “ready for prime time.” Until now. Thanks to Mike Mason for writing a clear, con- cise, gentle introduction to this new tool. After reading this book, I’m actually excited about the possibilities for version control that Subversion brings to the table. David Rupp Senior Software Engineer, Great-West Life & Annuity This was exactly the Subversion book I was waiting for. As a long-time Perforce and CVS user and administrator, and in my role as an agile tools coach, I wanted a compact book that told me just what I needed to know. This is it. Within a couple of hours I was up and running against remote Subversion servers, and setting up my own local servers too. Mike uses a lot of command-line examples to guide the reader, and as a Windows user I was worried at first. My fears were unfounded though—Mike’s examples were so clear that I think I’ll stick to using the command line from now on! I thoroughly recommend this book to anyone getting started using or administering Subversion. Mike Roberts Project co-Lead, CruiseControl.NET Pragmatic Version Control using Subversion Mike Mason The Pragmatic Bookshelf Raleigh, North Carolina Dallas, Texas Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and The Pragmatic Programmers, LLC was aware of a trademark claim, the designations have been printed in initial capital letters or in all capitals. The Pragmatic Starter Kit, The Pragmatic Programmer, Pragmatic Programming, Pragmatic Bookshelf and the linking g device are trademarks of The Pragmatic Programmers, LLC. Every precaution was taken in the preparation of this book. However, the publisher assumes no responsibility for errors or omissions, or for damages that may result from the use of information (including program listings) con- tained herein. Our Pragmatic courses, workshops, and other products can help you and your team create better software and have more fun. For more information, as well as the latest Pragmatic titles, please visit us at http://www.pragmaticprogrammer.com Copyright 2005 The Pragmatic Programmers LLC. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form, or by any means, electronic, mechanical, photo- copying, recording, or otherwise, without the prior consent of the publisher. Printed in the United States of America. ISBN 0-9745140-6-3 Printed on acid-free paper with 85% recycled, 30% post-consumer content. First printing, February 2005 Version: 2005-2-3 Contents Preface viii 1 Introduction 1 1.1 Version Control in Action . . . . . . . . . . . . . 2 1.2 Road Map . . . . . . . . . . . . . . . . . . . . . . 6 1.3 Why Choose Subversion . . . . . . . . . . . . . . 6 2 What Is Version Control? 9 2.1 The Repository . . . . . . . . . . . . . . . . . . . 9 2.2 What Should We Store? . . . . . . . . . . . . . . 11 2.3 Working Copies and Manipulating Files . . . . . 12 2.4 Projects, Directories, and Files . . . . . . . . . . 15 2.5 Where Do Versions Come In? . . . . . . . . . . . 16 2.6 Tags . . . . . . . . . . . . . . . . . . . . . . . . . 18 2.7 Branches . . . . . . . . . . . . . . . . . . . . . . 19 2.8 Merging . . . . . . . . . . . . . . . . . . . . . . . 22 2.9 Locking Options . . . . . . . . . . . . . . . . . . 23 2.10 Configuration Management (CM) . . . . . . . . . 26 3 Getting Started with Subversion 27 3.1 Installing Subversion . . . . . . . . . . . . . . . 27 3.2 Creating a Repository . . . . . . . . . . . . . . . 32 3.3 Creating a Simple Project . . . . . . . . . . . . . 33 3.4 Starting to Work with a Project . . . . . . . . . . 36 3.5 Making Changes . . . . . . . . . . . . . . . . . . 38 3.6 Updating the Repository . . . . . . . . . . . . . . 39 3.7 When Worlds Collide . . . . . . . . . . . . . . . . 43 3.8 Conflict Resolution . . . . . . . . . . . . . . . . . 45 CONTENTS vi 4 How To... 50 4.1 Our Basic Philosophy . . . . . . . . . . . . . . . 51 4.2 Important Steps When Using Version Control . 51 5 Accessing a Repository 53 5.1 Network Protocols . . . . . . . . . . . . . . . . . 53 5.2 Choosing a Networking Option . . . . . . . . . . 58 6 Common Subversion Commands 60 6.1 Checking Things Out . . . . . . . . . . . . . . . 60 6.2 Keeping Up-to-Date . . . . . . . . . . . . . . . . 62 6.3 Adding Files and Directories . . . . . . . . . . . 64 6.4 Properties . . . . . . . . . . . . . . . . . . . . . . 64 6.5 Copying and Moving Files and Directories . . . 73 6.6 Seeing What Has Changed . . . . . . . . . . . . 78 6.7 Handling Merge Conflicts . . . . . . . . . . . . . 84 6.8 Committing Changes . . . . . . . . . . . . . . . 89 6.9 Examining Change History . . . . . . . . . . . . 89 6.10 Removing a Change . . . . . . . . . . . . . . . . 93 7 Organizing Your Repository 97 7.1 A Simple Project . . . . . . . . . . . . . . . . . . 97 7.2 Multiple Projects . . . . . . . . . . . . . . . . . . 98 7.3 Multiple Repositories . . . . . . . . . . . . . . . 99 8 Using Tags and Branches 101 8.1 Tags and Branches . . . . . . . . . . . . . . . . . 102 8.2 Creating a Release Branch . . . . . . . . . . . . 105 8.3 Working in a Release Branch . . . . . . . . . . . 107 8.4 Generating a Release . . . . . . . . . . . . . . . 109 8.5 Fixing Bugs in a Release Branch . . . . . . . . . 111 8.6 Developer Experimental Branches . . . . . . . . 114 8.7 Working with Experimental Code . . . . . . . . 116 8.8 Merging the Experimental Branch . . . . . . . . 116 9 Creating a Project 118 9.1 Creating the Initial Project . . . . . . . . . . . . 119 9.2 Structure within the Project . . . . . . . . . . . 121 9.3 Sharing Code between Projects . . . . . . . . . . 125 Prepared exclusively for Kim Partridge CONTENTS vii 10 Third-Party Code 131 10.1 Binary Libraries . . . . . . . . . . . . . . . . . . 131 10.2 Libraries with Source Code . . . . . . . . . . . . 134 10.3 Keyword Expansion during Imports . . . . . . . 140 A Install, Network, Secure, and Administer 141 A.1 Installing Subversion . . . . . . . . . . . . . . . 141 A.2 Networking with svnserve . . . . . . . . . . . . . 142 A.3 Networking with svn+ssh . . . . . . . . . . . . . 144 A.4 Networking with Apache . . . . . . . . . . . . . . 147 A.5 Securing Subversion . . . . . . . . . . . . . . . . 153 A.6 Backing Up Your Repository . . . . . . . . . . . 158 B Migrating to Subversion 162 B.1 Getting cvs2svn . . . . . . . . . . . . . . . . . . . 163 B.2 Choosing How Much to Convert . . . . . . . . . 163 B.3 Converting Your Repository . . . . . . . . . . . . 164 C Third-Party Subversion Tools 166 C.1 TortoiseSVN . . . . . . . . . . . . . . . . . . . . . 166 C.2 IDE Integration . . . . . . . . . . . . . . . . . . . 173 C.3 Other Tools . . . . . . . . . . . . . . . . . . . . . 174 D Command Summary and Recipes 176 D.1 Subversion Command Summary . . . . . . . . . 176 D.2 Recipes . . . . . . . . . . . . . . . . . . . . . . . 186 E Other Resources 192 E.1 Online Resources . . . . . . . . . . . . . . . . . . 192 E.2 Bibliography . . . . . . . . . . . . . . . . . . . . 193 Prepared exclusively for Kim Partridge Preface I was pretty excited when I heard about the Pragmatic Starter Kit—finally some guidance on the basic stuff all projects need to get right. The opportunity to produce a Subversion edition of Pragmatic Version Control was one I couldn’t miss. Sub- version had previously saved me (and my team) from version control hell, and I wanted to do my part to help promote a great new version control system. Version control adds an immense amount to a project. It gives you a safety net, helps your team collaborate effectively, lets you organize your builds and QA, and even allows you to do some detective work if things go wrong. I hope this new edition of Pragmatic Version Control will help you and your team get started and succeed with Subversion. Acknowledgments I’d like to thank Dave and Andy for taking a chance on me being able to write the book and to thank Dave being such an excellent editor. I wasn’t really sure what I was getting myself into, and Dave’s advice and guidance were invaluable. The book received plenty of scrutiny by reviewers; I’d like to thank Brad Appleton, Branko Cˇibej, Martin Fowler, Steffen Gemkow, Robert Rasmussen, Mike Roberts, and David Rupp for their well-thought-out comments and suggestions. I’m frankly amazed by the quality of feedback I got—great sugges- tions, highly technical comments and plenty of people think- ing about the “bigger picture.” Everyone at ThoughtWorks has been really supportive of my book writing efforts, including several people who took the time to look through early drafts of the book, and I’d like to PREFACE ix thank all those who gave me advice and guidance. I’d particu- larly like to thank the Calgary office for welcoming me into the fold this year and for enabling me to get stuff finished when the crunch point came. Finally I’d like to thank Martin, Mike, and Michelle for making me believe I could really write the book and for their encour- agement along the way. Mike Mason December 2004 mike@mikemason.ca Typographic Conventions italic font Italics indicate a term that is being defined, or borrowed from another language. files Files (and directories) are indicated like this. commands Commands (and options such as -h) are shown like this. output Output (as well as things you might need to type) is indicated like this. If commands are too long for a single line they’re split onto multiple lines using a \ (backward slash). CVS Hint: This kind of text indicates a hint for users famil- iar with CVS. This warning sign indicates this material is more advanced and can be skipped on your first read- ing. “Joe the developer,” our cartoon friend, asks a related question that you may find useful. Prepared exclusively for Kim Partridge Chapter 1 Introduction This book tells you how to improve the effectiveness of your software development process using version control. Version control, sometimes called source code control, is the first leg of our project support tripod. We view the use of version control as mandatory on all projects. Version control offers many advantages to both teams and individuals: • It gives the team a project-wide undo button; nothing is final, and mistakes are easily rolled back. Imagine you’re using the world’s most sophisticated word processor. It has every function imaginable, except one. For some rea- son, they forgot to add support for a DELETE key. Think how carefully and slowly you’d have to type, particularly as you got near the end of a large document. One mis- take, and you’d have to start again. It’s the same with version control; having the ability to go back an hour, a day, or a week frees your team to work quickly, confident that they have a way of fixing mistakes. • It allows multiple developers to work on the same code base in a controlled manner. The team no longer loses changes when someone overwrites the edits made by another team member. • The version control system keeps a record of the changes made over time. If you come across some “surprising code,” it’s easy to find out who made the change, when, and (with any luck) why. VERSION CONTROL IN ACTION 2 • A version control system allows you to support multiple releases of your software at the same time as you con- tinue with the main line of development. With a version control system, there’s no longer a need for the team to stop work during a code freeze just before release. • Version control is a project-wide time machine, allowing you to dial in a date and see exactly what the project looked like on that date. This is useful for research, but it is essential for regenerating prior releases for cus- tomers with problems. This book focuses on version control from a project perspec- tive. Rather than simply listing the commands available in a version control system, we explain the tasks you need to per- form well in a successful project and then show how a version control system can help. Let’s start with a small story.... 1.1 Version Control in Action Fred rolls into the office eager to continue working on the new Orinoco book ordering system. (Why Orinoco? Fred’s com- pany uses the names of rivers for all internal projects.) After getting his first cup of coffee, Fred updates his local copy of the project’s source code with the latest versions from the cen- tral version control system. In the log that lists the updated files, he notices that Wilma has changed code in the basic Orders class. Fred gets worried that this change might affect his work, but today Wilma is off at the client’s site, installing the latest release, so he can’t ask her directly. Instead, Fred asks the version control system to display the notes associ- ated with the change to Orders. Wilma’s comment does little to reassure him: Added new deliveryPreferences field to the Orders class To find out what’s going on, he goes back to the version con- trol system and asks to see the actual changes made to the source file. He sees that Wilma has added a couple of instance variables, but they are set to default values, and nothing seems to change them. This might be a problem in the future, but it is nothing that will stop him today, so Fred continues working. Prepared exclusively for Kim Partridge VERSION CONTROL IN ACTION 3 As he works on his code, Fred adds a new class and a cou- ple of test classes to the system. Fred adds the names of the files he creates to the version control system as he creates them; the files themselves won’t be added until he commits his changes, but adding their names now means he won’t for- get to add them later. A couple of hours into the day, Fred has completed the first part of some new functionality. It passes its tests, and it won’t affect anything in the rest of the system, so he decides to check it all into the version control system, making it available to the rest of the team. Over the years, Fred has found that checking code in and out frequently works best for him: it’s a lot easier to reconcile the occasional conflict if you have to worry about only a couple of files rather than a week’s worth of changes from the whole team. Why You Should Never Answer the Phone Just as Fred is about to start the next round of coding, his phone rings. It’s Wilma, calling from the client’s site. It looks like there’s a bug in the release she is installing: printed invoices are not calculating sales tax on shipping amounts. The client is going ballistic, and they need a fix now. ...Unless You Use Version Control Fred double-checks the name of the release with Wilma and then tells the version control system to check out all the files in that version of the software. He puts it in a temporary directory on his PC, as he intends to delete it after he finishes the work. He now has two copies of the system’s source code on his computer: the trunk (the main line of development) and the version released to the client. Because he is about to fix a bug, he tells the version control system to tag his source code with a label. (He’ll add another tag when he has fixed the bug. These tags act as flags you leave behind to mark significant points in the development. By using consistently named tags before and after he makes the change, other folks in his team will be able to see exactly what changed should they look at it later.) Prepared exclusively for Kim Partridge VERSION CONTROL IN ACTION 4 In order to isolate the problem, Fred first writes a test. Sure enough, it looks like no one ever checked the sales tax cal- culation when shipping was involved, because his test imme- diately shows the problem. (Fred makes a note to raise this during this iteration’s review meeting; this is something that should never have gone out the door.) Sighing, Fred adds the line of code that adds shipping to the taxable total, com- piles, and checks that his test passes. He reruns the whole test suite as a quick sanity test and checks the fixed code back into the central version control system. Finally, he tags the release branch indicating that the bug is fixed. He sends a note off to QA, who is responsible for shipping emergency releases to the client. Using his tag, they’ll be able to instruct the build system to produce a delivery disk that includes his fix. Fred then phones Wilma and tells her the fix is in the hands of QA and should be with her soon. Having finished with this little distraction, Fred removes the source for the released code from his local machine: there’s no point in cluttering things up, and the changes he has made are safely tucked back into the central server. He then gets to wondering: is the sales tax bug he found in the released code also present in the current development version? The quick- est way to check is to add the test he wrote in the released ver- sion to the development test suite. He tells the version control system to merge that particular change in the release branch into the appropriate file in the development copy. The merge process takes whatever changes were made to the release files and makes the same changes to the development ver- sion. When he runs the tests, his new test fails: the bug is indeed present. He then moves his fix from the release branch into the development version. (He doesn’t need the release branch’s code on his machine to do any of this; all the changes are being fetched from the central version control system.) Once he has the tests all running again, he commits this change into the version control system. That’s one less bug that’ll bite the team next time. Crisis over, Fred gets back to working on his own tasks for the day. He spends a happy afternoon writing tests and code and toward the end of the day decides he is done. While he has been working, other folks in his team have also been making Prepared exclusively for Kim Partridge VERSION CONTROL IN ACTION 5 changes, so he uses the version control system to take their work and apply it his local copy of the source. He runs the tests one last time and then checks his changes back in, ready to start work the next day. Tomorrow... Unfortunately, the next day brings its own surprises. Over- night Fred’s central heating finally gives up the ghost. As Fred lives in Minnesota, and as it’s February, this isn’t something to be taken lightly. Fred calls into work to say he’ll be out most of the day waiting for the repair folks to arrive. However, that doesn’t mean he has to stop working. Accessing his office network using a secure connection over the public Internet, Fred checks out the latest development code onto his laptop. Because he checked in before he went home the previous night, everything is there and up-to-date. He con- tinues to work at home, wrapped in a blanket and sitting by the fire. Before he stops for the day, he checks his changes in from the laptop so they’ll be available to him at work the next day. Life is good (except for the heating repair bill).

该用户的其他资料

  • 名称/格式
  • 评分
  • 下载次数
  • 资料大小
  • 上传时间

用户评论

0/200
    暂无评论
上传我的资料

相关资料

资料评价:

/ 211
所需积分:0 立即下载
返回
顶部
举报
资料
关闭

温馨提示

感谢您对爱问共享资料的支持,精彩活动将尽快为您呈现,敬请期待!