This pocket guide is the perfect on-the-job companion to Git, the distributed version control system. It provides a compact, readable introduction to Git for new users, as well as a reference to common commands and procedures for those of you with Git experience.Written for Git version 1.8.2, this handy task-oriented guide is organized around the basic version control functions you need, such as making commits, fixing mistakes, merging, and searching history.Examine the state of your project at earlier points in timeLearn the basics of creating and making changes to a repositoryCreate branches so many people can work on a project simultaneouslyMerge branches and reconcile the changes among themClone an existing repository and share changes with push/pull commandsExamine and change your repository’s commit historyAccess remote repositories, using different network protocolsGet recipes for accomplishing a variety of common tasks Cover 1 Copyright 4 Table of Contents 5 Preface 11 What Is Git? 11 Goals of This Book 13 Conventions Used in This Book 14 Unix 14 Shell 15 Command Syntax 15 Typography 15 Using Code Examples 16 Safari® Books Online 17 How to Contact Us 17 Acknowledgments 18 Chapter 1. Understanding Git 19 Overview 20 Terminology 20 Branches 21 Sharing Work 22 The Object Store 24 Blob 24 Tree 25 Commit 26 Tag 29 Object IDs and SHA-1 29 Security 32 Where Objects Live 33 The Commit Graph 34 Refs 35 Related Commands 36 Branches 37 The Index 40 Merging 42 Merging Content 43 Merging History 43 Push and Pull 44 Notes 49 Chapter 2. Getting Started 51 Basic Configuration 51 Personal Identification 53 Text Editor 53 Commit ID Abbreviation 54 Pagination 54 Color 55 Cryptographic Keys 55 Command Aliases 56 Getting Help 56 References 57 Creating a New, Empty Repository 57 Selected Options 58 Importing an Existing Project 59 Ignoring Files 60 Syntax of “Ignore Patterns” 62 Chapter 3. Making Commits 65 Changing the Index 65 Adding a New File 65 Adding the Changes to an Existing File 66 Adding Partial Changes 66 Shortcuts 67 Removing a File 67 Renaming a File 68 Unstaging Changes 70 Making a Commit 70 Commit Messages 70 What Makes a Good Commit? 71 Shortcuts 72 Empty Directories 73 A Commit Workflow 73 Chapter 4. Undoing and Editing Commits 75 Changing the Last Commit 76 Double Oops! 77 Discarding the Last Commit 79 Discarding Any Number of Commits 79 Undoing a Commit 80 Partial Undo 81 Editing a Series of Commits 82 Conflicts 84 The exec Action 85 Chapter 5. Branching 87 The Default Branch, master 88 Making a New Branch 88 Switching Branches 90 Uncommitted Changes 91 Untracked Files 92 Losing Your Head 92 Deleting a Branch 93 Renaming a Branch 96 Chapter 6. Tracking Other Repositories 97 Cloning a Repository 97 Clones and Hard Links 98 Bare Repositories 100 Reference Repositories 100 Local, Remote, and Tracking Branches 102 Synchronization: Push and Pull 104 Pulling 104 Pushing 105 Push Defaults 106 Pull with Rebase 107 Notes 109 Access Control 112 Chapter 7. Merging 113 Merge Conflicts 116 Resolving Merge Conflicts 120 Notes 122 Details on Merging 123 Merge Tools 125 Notes 126 Custom Merge Tools 126 Merge Strategies 127 Why the Octopus? 129 Reusing Previous Merge Decisions 130 Chapter 8. Naming Commits 133 Naming Individual Commits 133 Commit ID 133 Ref Name 134 Names Relative to a Given Commit 135 Names Relative to the Reflog 136 The Upstream Branch 138 Matching a Commit Message 139 Following Chains 140 Addressing Pathnames 140 Naming Sets of Commits 141 Chapter 9. Viewing History 145 Command Format 145 Output Formats 146 Defining Your Own Formats 148 Notes 149 Limiting Commits to Be Shown 150 Regular Expressions 151 Reflog 152 Decoration 152 Date Style 153 Listing Changed Files 154 Showing and Following Renames or Copies 156 Detecting Copies 157 Rewriting Names and Addresses: The “mailmap” 157 Shortening Names 159 Searching for Changes: The “pickaxe” 160 Showing Diffs 160 Color 161 Word Diff 161 Comparing Branches 162 Displaying Sides 163 Showing Notes 164 Commit Ordering 164 History Simplification 165 Related Commands 165 git cherry 165 git shortlog 166 Chapter 10. Editing History 167 Rebasing 167 Undoing a Rebase 170 Importing from One Repository to Another 171 Importing Disconnected History 172 Importing Linear History 174 Importing Nonlinear History 175 Commit Surgery: git replace 177 Keeping It Real 179 The Big Hammer: git filter-branch 180 Examples 183 Notes 184 Chapter 11. Understanding Patches 185 Applying Plain Diffs 187 Patches with Commit Information 188 Chapter 12. Remote Access 191 SSH 191 HTTP 195 Storing Your Username 195 Storing Your Password 196 References 197 Chapter 13. Miscellaneous 199 git cherry-pick 199 git notes 200 git notes Subcommands 201 git grep 202 Combining Regular Expressions 202 What to Search 203 What to Show 203 How to Match 204 git rev-parse 205 git clean 205 git stash 206 Subcommands 207 git show 209 git tag 209 Deleting a Tag from a Remote 211 Following Tags 211 Backdating Tags 212 git diff 212 git diff 212 git diff --staged 212 git diff 212 git diff 212 Options and Arguments 213 git instaweb 213 Git Hooks 214 Visual Tools 215 Submodules 215 Chapter 14. How Do I...? 217 ...Make and Use a Central Repository? 217 ...Fix the Last Commit I Made? 218 ...Edit the Previous n Commits? 218 ...Undo My Last n Commits? 218 ...Reuse the Message from an Existing Commit? 219 ...Reapply an Existing Commit from Another Branch? 219 ...List Files with Conflicts when Merging? 219 ...Get a Summary of My Branches? 219 ...Get a Summary of My Working Tree and Index State? 220 ...Stage All the Current Changes to My Working Files? 220 ...Show the Changes to My Working Files? 220 ...Save and Restore My Working Tree and Index Changes? 221 ...Add a Downstream Branch Without Checking It Out? 221 ...List the Files in a Specific Commit? 221 ...Show the Changes Made by a Commit? 221 ...Get Tab Completion of Branch Names, Tags, and So On? 222 ...List All Remotes? 222 ...Change the URL for a Remote? 222 ...Remove Old Remote-Tracking Branches? 223 ...Have git log: 223 Find Commits I Made but Lost? 223 Not Show the diffs for Root Commits? 223 Show the Changes for Each Commit? 223 Show the Committer as well as the Author? 223 Index 225 La 4e de couverture porte: "This pocket guide is the perfect on-the-job companion to Git, the distributed version control system. It provides a compact, readable introduction to Git for new users, as well as a reference to common commands and procedures for those of you with Git experience. Written for Git version 1.8.2, this handy task-oriented guide is organized around the basic version control functions you need, such as making commits, fixing mistakes, merging, and searching history. Examine the state of your project at earlier points in time, learn the basics of creating and making changes to a repository, create branches so many people can work on a project simultaneously, merge branches and reconcile the changes among them, clone an existing repository and share changes with push/pull commands, examine and change your repository's commit history, access remote repositories, using different network protocols, get recipes for accomplishing a variety of common tasks."