ebook img

Git in Practice PDF

273 Pages·2014·6.435 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Git in Practice

Mike McQuaid Foreword by Scott Chacon I T NCLUDES 66 ECHNIQUES M A N N I N G www.it-ebooks.info Git in Practice www.it-ebooks.info www.it-ebooks.info Git in Practice MIKE MCQUAID MANNING SHELTER ISLAND www.it-ebooks.info For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact Special Sales Department Manning Publications Co. 20 Baldwin Road PO Box 761 Shelter Island, NY 11964 Email: [email protected] ©2015 by Manning Publications Co. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps. Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine. Manning Publications Co. Development editor: Dan Maharry 20 Baldwin Road Technical development editor: Glenn Burnside PO Box 761 Copyeditor: Benjamin Berg Shelter Island, NY 11964 Proofreader: Tiffany Taylor Typesetter: Dottie Marsico Cover designer: Marija Tudor ISBN 9781617291975 Printed in the United States of America 1 2 3 4 5 6 7 8 9 10 – EBM – 19 18 17 16 15 14 www.it-ebooks.info brief contents P 1 I G .....................................................1 ART NTRODUCTION TO IT 1 ■ Local Git 3 2 ■ Remote Git 24 P 2 G ..............................................................51 ART IT ESSENTIALS 3 ■ Filesystem interactions 53 4 ■ History visualization 68 5 ■ Advanced branching 84 6 ■ Rewriting history and disaster recovery 104 P 3 A G ............................................................127 ART DVANCED IT 7 ■ Personalizing Git 129 8 ■ Vendoring dependencies as submodules 141 9 ■ Working with Subversion 151 10 ■ GitHub pull requests 163 11 ■ Hosting a repository 174 v www.it-ebooks.info vi BRIEF CONTENTS P 4 G ......................................................185 ART IT BEST PRACTICES 12 ■ Creating a clean history 187 13 ■ Merging vs. rebasing 196 14 ■ Recommended team workflows 206 www.it-ebooks.info contents foreword xiii preface xv acknowledgments xvii about this book xviii about the cover illustartion xxii P 1 I G ........................................1 ART NTRODUCTION TO IT 1 Local Git 3 1.1 Why do programmers use Git? 3 1.2 Initial setup 4 TECHNIQUE 1 Creating a repository: git init 5 1.3 .git subdirectory 6 1.4 Creating a new commit: git add, git commit 7 TECHNIQUE 2 Building a new commit in the index staging area: git add 8 TECHNIQUE 3 Committing changes to files: git commit 10 TECHNIQUE 4 Viewing history: git log, gitk, gitx 13 1.5 Rewriting history 18 TECHNIQUE 5 Viewing the differences between commits: git diff 18 1.6 Diff formats 21 vii www.it-ebooks.info viii CONTENTS 1.7 Refs 22 1.8 Summary 23 2 Remote Git 24 TECHNIQUE 6 Adding a remote repository: git remote add 24 2.1 Authoritative version storage 27 TECHNIQUE 7 Pushing changes to a remote repository: git push 28 TECHNIQUE 8 Cloning a remote/GitHub repository onto your local machine: git clone 30 TECHNIQUE 9 Pulling changes from another repository: git pull 32 TECHNIQUE 10 Fetching changes from a remote without modifying local branches: git fetch 35 TECHNIQUE 11 Creating a new local branch from the current branch: git branch 37 TECHNIQUE 12 Checking out a local branch: git checkout 40 TECHNIQUE 13 Pushing a local branch remotely 42 TECHNIQUE 14 Merging an existing branch into the current branch: git merge 44 2.2 Merge conflicts 46 2.3 Rebasing 47 TECHNIQUE 15 Deleting a remote branch 47 TECHNIQUE 16 Deleting the current local branch after merging 49 2.4 Summary 50 P 2 G .................................................51 ART IT ESSENTIALS 3 Filesystem interactions 53 TECHNIQUE 17 Renaming or moving a file: git mv 54 TECHNIQUE 18 Removing a file: git rm 55 TECHNIQUE 19 Resetting files to the last commit: git reset 56 TECHNIQUE 20 Deleting untracked files: git clean 57 TECHNIQUE 21 Ignoring files: .gitignore 59 TECHNIQUE 22 Deleting ignored files 60 TECHNIQUE 23 Temporarily stashing some changes: git stash 61 TECHNIQUE 24 Reapplying stashed changes: git stash pop 63 TECHNIQUE 25 Clearing stashed changes: git stash clear 64 TECHNIQUE 26 Assuming files are unchanged 64 TECHNIQUE 27 Listing assumed-unchanged files 65 TECHNIQUE 28 Stopping assuming files are unchanged 66 3.1 Summary 67 www.it-ebooks.info CONTENTS ix 4 History visualization 68 TECHNIQUE 29 Listing only certain commits 69 4.1 git show 70 TECHNIQUE 30 Listing commits with different formatting 71 4.2 Custom output format 74 4.3 Releasing logs: git shortlog 75 4.4 The ultimate log output 75 TECHNIQUE 31 Showing who last changed each line of a file: git blame 76 TECHNIQUE 32 Finding which commit caused a particular bug: git bisect 78 4.5 Automating git bisect 82 4.6 Summary 83 5 Advanced branching 84 TECHNIQUE 33 Merging branches and always creating a merge commit 85 5.1 Merge strategies 87 TECHNIQUE 34 Resolving a merge conflict 88 5.2 Using a graphical merge tool 93 TECHNIQUE 35 Resolving each merge conflict only once: git rerere 94 TECHNIQUE 36 Creating a tag: git tag 95 TECHNIQUE 37 Generating a version number based on previous tags: git describe 97 TECHNIQUE 38 Adding a single commit to the current branch: git cherry-pick 98 TECHNIQUE 39 Reverting a previous commit: git revert 101 TECHNIQUE 40 Listing what branches contain a commit: git cherry 102 5.3 Summary 103 6 Rewriting history and disaster recovery 104 TECHNIQUE 41 Listing all changes including history rewrites: git reflog 105 6.1 Avoiding and recovering from disasters 106 TECHNIQUE 42 Resetting a branch to a previous commit: git reset 107 TECHNIQUE 43 Rebasing commits on top of another branch: git rebase 110 www.it-ebooks.info

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.