Distributed Revision Control with Mercurial
Total Page:16
File Type:pdf, Size:1020Kb
Distributed revision control with Mercurial Bryan O’Sullivan Copyright c 2006, 2007 Bryan O’Sullivan. This material may be distributed only subject to the terms and conditions set forth in version 1.0 of the Open Publication License. Please refer to Appendix D for the license text. This book was prepared from rev 028543f67bea, dated 2008-08-20 15:27 -0700, using rev a58a611c320f of Mercurial. Contents Contents i Preface 2 0.1 This book is a work in progress ...................................... 2 0.2 About the examples in this book ..................................... 2 0.3 Colophon—this book is Free ....................................... 2 1 Introduction 3 1.1 About revision control .......................................... 3 1.1.1 Why use revision control? .................................... 3 1.1.2 The many names of revision control ............................... 4 1.2 A short history of revision control .................................... 4 1.3 Trends in revision control ......................................... 5 1.4 A few of the advantages of distributed revision control ......................... 5 1.4.1 Advantages for open source projects ............................... 6 1.4.2 Advantages for commercial projects ............................... 6 1.5 Why choose Mercurial? .......................................... 7 1.6 Mercurial compared with other tools ................................... 7 1.6.1 Subversion ............................................ 7 1.6.2 Git ................................................ 8 1.6.3 CVS ................................................ 8 1.6.4 Commercial tools ......................................... 9 1.6.5 Choosing a revision control tool ................................. 9 1.7 Switching from another tool to Mercurial ................................ 9 2 A tour of Mercurial: the basics 10 2.1 Installing Mercurial on your system ................................... 10 2.1.1 Linux ............................................... 10 2.1.2 Solaris .............................................. 10 2.1.3 Mac OS X ............................................ 11 2.1.4 Windows ............................................. 11 2.2 Getting started ............................................... 11 2.2.1 Built-in help ........................................... 11 2.3 Working with a repository ........................................ 12 2.3.1 Making a local copy of a repository ............................... 12 2.3.2 What’s in a repository? ...................................... 12 2.4 A tour through history .......................................... 13 2.4.1 Changesets, revisions, and talking to other people ........................ 14 2.4.2 Viewing specific revisions .................................... 15 2.4.3 More detailed information .................................... 16 i 2.5 All about command options ........................................ 16 2.6 Making and reviewing changes ...................................... 17 2.7 Recording changes in a new changeset .................................. 18 2.7.1 Setting up a username ...................................... 18 2.7.2 Writing a commit message .................................... 19 2.7.3 Writing a good commit message ................................. 19 2.7.4 Aborting a commit ........................................ 20 2.7.5 Admiring our new handiwork .................................. 20 2.8 Sharing changes .............................................. 20 2.8.1 Pulling changes from another repository ............................. 20 2.8.2 Updating the working directory ................................. 21 2.8.3 Pushing changes to another repository .............................. 23 2.8.4 Sharing changes over a network ................................. 23 3 A tour of Mercurial: merging work 25 3.1 Merging streams of work ......................................... 25 3.1.1 Head changesets ......................................... 27 3.1.2 Performing the merge ...................................... 28 3.1.3 Committing the results of the merge ............................... 29 3.2 Merging conflicting changes ....................................... 29 3.2.1 Using a graphical merge tool ................................... 30 3.2.2 A worked example ........................................ 30 3.3 Simplifying the pull-merge-commit sequence .............................. 33 4 Behind the scenes 35 4.1 Mercurial’s historical record ....................................... 35 4.1.1 Tracking the history of a single file ............................... 35 4.1.2 Managing tracked files ...................................... 35 4.1.3 Recording changeset information ................................ 35 4.1.4 Relationships between revisions ................................. 35 4.2 Safe, efficient storage ........................................... 36 4.2.1 Efficient storage ......................................... 37 4.2.2 Safe operation .......................................... 37 4.2.3 Fast retrieval ........................................... 37 4.2.4 Identification and strong integrity ................................ 38 4.3 Revision history, branching, and merging ................................ 38 4.4 The working directory .......................................... 38 4.4.1 What happens when you commit ................................. 39 4.4.2 Creating a new head ....................................... 39 4.4.3 Merging heads .......................................... 39 4.5 Other interesting design features ..................................... 40 4.5.1 Clever compression ........................................ 40 4.5.2 Read/write ordering and atomicity ................................ 41 4.5.3 Concurrent access ........................................ 41 4.5.4 Avoiding seeks .......................................... 41 4.5.5 Other contents of the dirstate ................................... 42 5 Mercurial in daily use 47 5.1 Telling Mercurial which files to track ................................... 47 5.1.1 Explicit versus implicit file naming ............................... 47 5.1.2 Aside: Mercurial tracks files, not directories ........................... 48 5.2 How to stop tracking a file ........................................ 49 ii 5.2.1 Removing a file does not affect its history ............................ 49 5.2.2 Missing files ........................................... 49 5.2.3 Aside: why tell Mercurial explicitly to remove a file? ...................... 50 5.2.4 Useful shorthand—adding and removing files in one step .................... 50 5.3 Copying files ............................................... 50 5.3.1 The results of copying during a merge .............................. 51 5.3.2 Why should changes follow copies? ............................... 52 5.3.3 How to make changes not follow a copy ............................. 52 5.3.4 Behaviour of the “hg copy” command ............................. 52 5.4 Renaming files .............................................. 53 5.4.1 Renaming files and merging changes .............................. 54 5.4.2 Divergent renames and merging ................................. 54 5.4.3 Convergent renames and merging ................................ 55 5.4.4 Other name-related corner cases ................................. 55 5.5 Recovering from mistakes ........................................ 55 6 Collaborating with other people 57 6.1 Mercurial’s web interface ......................................... 57 6.2 Collaboration models ........................................... 57 6.2.1 Factors to keep in mind ...................................... 57 6.2.2 Informal anarchy ......................................... 58 6.2.3 A single central repository .................................... 58 6.2.4 Working with multiple branches ................................. 58 6.2.5 Feature branches ......................................... 61 6.2.6 The release train ......................................... 61 6.2.7 The Linux kernel model ..................................... 61 6.2.8 Pull-only versus shared-push collaboration ........................... 62 6.2.9 Where collaboration meets branch management ......................... 62 6.3 The technical side of sharing ....................................... 62 6.4 Informal sharing with “hg serve” .................................... 62 6.4.1 A few things to keep in mind ................................... 63 6.5 Using the Secure Shell (ssh) protocol ................................... 63 6.5.1 How to read and write ssh URLs ................................. 63 6.5.2 Finding an ssh client for your system .............................. 64 6.5.3 Generating a key pair ....................................... 64 6.5.4 Using an authentication agent .................................. 65 6.5.5 Configuring the server side properly ............................... 65 6.5.6 Using compression with ssh ................................... 66 6.6 Serving over HTTP using CGI ...................................... 67 6.6.1 Web server configuration checklist ................................ 67 6.6.2 Basic CGI configuration ..................................... 67 6.6.3 Sharing multiple repositories with one CGI script ........................ 69 6.6.4 Downloading source archives .................................. 70 6.6.5 Web configuration options .................................... 70 7 File names and pattern matching 73 7.1 Simple file naming ...........................................