logo资料库

Version Control with Git(2nd) 无水印pdf.pdf

第1页 / 共454页
第2页 / 共454页
第3页 / 共454页
第4页 / 共454页
第5页 / 共454页
第6页 / 共454页
第7页 / 共454页
第8页 / 共454页
资料共454页,剩余部分请下载后查看
Cover
Table of Contents
Preface
Audience
Assumed Framework
Book Layout and Omissions
Conventions Used in This Book
Using Code Examples
Safari® Books Online
How to Contact Us
Acknowledgments
Attributions
1. Introduction
Background
The Birth of Git
Precedents
Timeline
What's in a Name?
2. Installing Git
Using Linux Binary Distributions
Debian/Ubuntu
Other Binary Distributions
Obtaining a Source Release
Building and Installing
Installing Git on Windows
Installing the Cygwin Git Package
Installing Standalone Git (msysGit)
3. Getting Started
The Git Command Line
Quick Introduction to Using Git
Creating an Initial Repository
Adding a File to Your Repository
Configuring the Commit Author
Making Another Commit
Viewing Your Commits
Viewing Commit Differences
Removing and Renaming Files in Your Repository
Making a Copy of Your Repository
Configuration Files
Configuring an Alias
Inquiry
4. Basic Git Concepts
Basic Concepts
Repositories
Git Object Types
Index
Content-Addressable Names
Git Tracks Content
Pathname Versus Content
Pack Files
Object Store Pictures
Git Concepts at Work
Inside the .git Directory
Objects, Hashes, and Blobs
Files and Trees
A Note on Git's Use of SHA1
Tree Hierarchies
Commits
Tags
5. File Management and the Index
It's All About the Index
File Classifications in Git
Using git add
Some Notes on Using git commit
Using git commit --all
Writing Commit Log Messages
Using git rm
Using git mv
A Note on Tracking Renames
The .gitignore File
A Detailed View of Git's Object Model and Files
6. Commits
Atomic Changesets
Identifying Commits
Absolute Commit Names
refs and symrefs
Relative Commit Names
Commit History
Viewing Old Commits
Commit Graphs
Using gitk to View the Commit Graph
Commit Ranges
Finding Commits
Using git bisect
Using git blame
Using Pickaxe
7. Branches
Reasons for Using Branches
Branch Names
Dos and Don'ts in Branch Names
Using Branches
Creating Branches
Listing Branch Names
Viewing Branches
Checking out Branches
A Basic Example of Checking out a Branch
Checking out When You Have Uncommitted Changes
Merging Changes into a Different Branch
Creating and Checking out a New Branch
Detached HEAD Branches
Deleting Branches
8. Diffs
Forms of the git diff Command
Simple git diff Example
git diff and Commit Ranges
git diff with Path Limiting
Comparing How Subversion and Git Derive diffs
9. Merges
Merge Examples
Preparing for a Merge
Merging Two Branches
A Merge with a Conflict
Working with Merge Conflicts
Locating Conflicted Files
Inspecting Conflicts
git diff with conflicts
git log with conflicts
How Git Keeps Track of Conflicts
Finishing Up a Conflict Resolution
Aborting or Restarting a Merge
Merge Strategies
Degenerate Merges
Normal Merges
Recursive merges
Octopus merges
Specialty Merges
Applying Merge Strategies
Merge Drivers
How Git Thinks About Merges
Merges and Git's Object Model
Squash Merges
Why Not Just Merge Each Change One by One?
10. Altering Commits
Caution About Altering History
Using git reset
Using git cherry-pick
Using git revert
reset, revert, and checkout
Changing the Top Commit
Rebasing Commits
Using git rebase -i
rebase Versus merge
11. The Stash and the Reflog
The Stash
The Reflog
12. Remote Repositories
Repository Concepts
Bare and Development Repositories
Repository Clones
Remotes
Tracking Branches
Referencing Other Repositories
Referring to Remote Repositories
The refspec
Example Using Remote Repositories
Creating an Authoritative Repository
Make Your Own Origin Remote
Developing in Your Repository
Pushing Your Changes
Adding a New Developer
Getting Repository Updates
The fetch step
The merge or rebase step
Should you merge or rebase?
Remote Repository Development Cycle in Pictures
Cloning a Repository
Alternate Histories
Non–Fast-Forward Pushes
Fetching the Alternate History
Merging Histories
Merge Conflicts
Pushing a Merged History
Remote Configuration
Using git remote
Using git config
Using Manual Editing
Working with Tracking Branches
Creating Tracking Branches
Ahead and Behind
Adding and Deleting Remote Branches
Bare Repositories and git push
13. Repository Management
A Word About Servers
Publishing Repositories
Repositories with Controlled Access
Repositories with Anonymous Read Access
Publishing repositories using git-daemon
Publishing repositories using an HTTP daemon
Publishing a repository using Smart HTTP
Publishing via Git and HTTP daemons
Repositories with Anonymous Write Access
Publishing Your Repository to GitHub
Repository Publishing Advice
Repository Structure
The Shared Repository Structure
Distributed Repository Structure
Repository Structure Examples
Living with Distributed Development
Changing Public History
Separate Commit and Publish Steps
No One True History
Knowing Your Place
Upstream and Downstream Flows
The Maintainer and Developer Roles
Maintainer–Developer Interaction
Role Duality
Working with Multiple Repositories
Your Own Workspace
Where to Start Your Repository
Converting to a Different Upstream Repository
Using Multiple Upstream Repositories
Forking Projects
Isn't forking a project bad?
Reconciling forks
Forking projects at GitHub
14. Patches
Why Use Patches?
Generating Patches
Patches and Topological Sorts
Mailing Patches
Applying Patches
Bad Patches
Patching Versus Merging
15. Hooks
Installing Hooks
Example Hooks
Creating Your First Hook
Available Hooks
Commit-Related Hooks
Patch-Related Hooks
Push-Related Hooks
Other Local Repository Hooks
16. Combining Projects
The Old Solution: Partial Checkouts
The Obvious Solution: Import the Code into Your Project
Importing Subprojects by Copying
Importing Subprojects with git pull -s subtree
Submitting Your Changes Upstream
The Automated Solution: Checking out Subprojects Using Custom Scripts
The Native Solution: gitlinks and git submodule
Gitlinks
The git submodule Command
17. Submodule Best Practices
Submodule Commands
Why Submodules?
Submodules Preparation
Why Read Only?
Why Not Read Only?
Examining the Hashes of Submodule Commits
Credential Reuse
Use Cases
Multilevel Nesting of Repos
Submodules on the Horizon
18. Using Git with Subversion Repositories
Example: A Shallow Clone of a Single Branch
Making Your Changes in Git
Fetching Before Committing
Committing Through git svn rebase
Pushing, Pulling, Branching, and Merging with git svn
Keeping Your Commit IDs Straight
Cloning All the Branches
Sharing Your Repository
Merging Back into Subversion
How dcommit handles merges
Miscellaneous Notes on Working with Subversion
svn:ignore Versus .gitignore
Reconstructing the git-svn Cache
19. Advanced Manipulations
Using git filter-branch
Examples Using git filter-branch
Using git filter-branch to expunge a file
Using filter-branch to edit a commit message
filter-branch Pitfalls
How I Learned to Love git rev-list
Date-Based Checkout
Date-based checkout cautions
Retrieve Old Version of a File
Interactive Hunk Staging
Recovering a Lost Commit
The git fsck Command
Reconnecting a Lost Commit
20. Tips, Tricks, and Techniques
Interactive Rebase with a Dirty Working Directory
Remove Left-Over Editor Files
Garbage Collection
Split a Repository
Tips for Recovering Commits
Subversion Conversion Tips
General Advice
Remove a Trunk After an SVN Import
Removing SVN Commit IDs
Manipulating Branches from Two Repositories
Recovering from an Upstream Rebase
Make Your Own Git Command
Quick Overview of Changes
Cleaning Up
Using git-grep to Search a Repository
Updating and Deleting refs
Following Files that Moved
Keep, But Don't Track, This File
Have You Been Here Before?
21. Git and GitHub
Repo for Public Code
Creating a GitHub Repository
Social Coding on Open Source
Watchers
News Feed
Forks
Creating Pull Requests
Managing Pull Requests
Notifications
Finding Users, Projects, and Code
Wikis
GitHub Pages (Git for Websites)
In-Page Code Editor
Subversion Bridge
Tags Automatically Becoming Archives
Organizations
REST API
Social Coding on Closed Source
Eventual Open Sourcing
Coding Models
GitHub Enterprise
GitHub in Sum
Index
SECOND EDITION Version Control with Git Jon Loeliger and Matthew McCullough Beijing•Cambridge•Farnham•Köln•Sebastopol•Tokyo
Version Control with Git, Second Edition by Jon Loeliger and Matthew McCullough Copyright © 2012 Jon Loeliger. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://my.safaribooksonline.com). For more information, contact our corporate/institutional sales department: 800-998-9938 or corporate@oreilly.com. Indexer: Nancy Guenther on behalf of Potomac Indexing, LLC Cover Designer: Karen Montgomery Interior Designer: David Futato Illustrators: Robert Romano and Rebecca Demarest Editor: Andy Oram Production Editor: Copyeditor: Absolute Service, Inc. Proofreader: Absolute Service, Inc. Iris Febres May 2009: August 2012: First Edition. Second Edition. Revision History for the Second Edition: 2012-08-03 First release See http://oreilly.com/catalog/errata.csp?isbn=9781449316389 for release details. Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc. Version Control with Git, the image of the image of a long-eared bat, and related trade dress are trademarks of O’Reilly Media, Inc. 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 O’Reilly Media, Inc., was aware of a trademark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this book, the publisher and authors assume no responsibility for errors or omissions, or for damages resulting from the use of the information con- tained herein. ISBN: 978-1-449-31638-9 [LSI] 1344953139
Table of Contents Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1 Background The Birth of Git 2 4 Precedents 6 Timeline What’s in a Name? 7 1. 2. Debian/Ubuntu Other Binary Distributions Installing Git . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 9 Using Linux Binary Distributions 9 10 11 12 13 14 15 Obtaining a Source Release Building and Installing Installing Git on Windows Installing the Cygwin Git Package Installing Standalone Git (msysGit) 3. Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 19 21 21 22 24 24 25 26 26 27 28 The Git Command Line Quick Introduction to Using Git Creating an Initial Repository Adding a File to Your Repository Configuring the Commit Author Making Another Commit Viewing Your Commits Viewing Commit Differences Removing and Renaming Files in Your Repository Making a Copy of Your Repository Configuration Files iii
Configuring an Alias Inquiry 30 30 Basic Concepts Repositories Git Object Types Index Content-Addressable Names Git Tracks Content Pathname Versus Content Pack Files 4. Basic Git Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 31 31 32 33 33 34 35 36 36 39 39 40 41 42 43 44 46 Inside the .git Directory Objects, Hashes, and Blobs Files and Trees A Note on Git’s Use of SHA1 Tree Hierarchies Commits Tags Object Store Pictures Git Concepts at Work 5. File Management and the Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 It’s All About the Index 48 48 File Classifications in Git 50 Using git add 52 Some Notes on Using git commit 52 54 54 56 57 58 60 Using git rm Using git mv A Note on Tracking Renames The .gitignore File A Detailed View of Git’s Object Model and Files Using git commit --all Writing Commit Log Messages Atomic Changesets Identifying Commits 6. Commits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 66 67 67 68 69 72 72 Absolute Commit Names refs and symrefs Relative Commit Names Commit History Viewing Old Commits iv | Table of Contents
Commit Graphs Commit Ranges Finding Commits Using git bisect Using git blame Using Pickaxe 74 78 83 83 87 88 Dos and Don’ts in Branch Names Reasons for Using Branches Branch Names Using Branches Creating Branches Listing Branch Names Viewing Branches Checking out Branches 7. Branches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 89 90 91 91 93 94 94 97 97 98 99 101 102 103 A Basic Example of Checking out a Branch Checking out When You Have Uncommitted Changes Merging Changes into a Different Branch Creating and Checking out a New Branch Detached HEAD Branches Deleting Branches 8. Diffs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 108 112 115 117 119 Forms of the git diff Command Simple git diff Example git diff and Commit Ranges git diff with Path Limiting Comparing How Subversion and Git Derive diffs Working with Merge Conflicts Preparing for a Merge Merging Two Branches A Merge with a Conflict 9. Merges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 121 122 122 124 128 129 129 134 135 137 137 140 Locating Conflicted Files Inspecting Conflicts How Git Keeps Track of Conflicts Finishing Up a Conflict Resolution Aborting or Restarting a Merge Degenerate Merges Merge Examples Merge Strategies Table of Contents | v
Normal Merges Specialty Merges Applying Merge Strategies Merge Drivers How Git Thinks About Merges Merges and Git’s Object Model Squash Merges Why Not Just Merge Each Change One by One? 142 143 144 145 146 146 147 148 Caution About Altering History Using git reset Using git cherry-pick Using git revert reset, revert, and checkout Changing the Top Commit Rebasing Commits 10. Altering Commits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 152 154 161 163 164 165 167 170 174 Using git rebase -i rebase Versus merge 11. The Stash and the Reflog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 181 189 The Stash The Reflog Repository Concepts Referencing Other Repositories Referring to Remote Repositories The refspec Example Using Remote Repositories Bare and Development Repositories Repository Clones Remotes Tracking Branches 12. Remote Repositories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195 196 196 197 198 199 200 200 202 204 205 206 208 209 210 212 217 217 218 Creating an Authoritative Repository Make Your Own Origin Remote Developing in Your Repository Pushing Your Changes Adding a New Developer Getting Repository Updates Remote Repository Development Cycle in Pictures Cloning a Repository Alternate Histories vi | Table of Contents
分享到:
收藏