You are previewing Git Version Control Cookbook.
O'Reilly logo
Git Version Control Cookbook

Book Description

In Detail

Starting with the Git data model, you will learn how Git stores files and how it looks at commits. You will then learn how you can recover from mistakes; from committing on the wrong branch to recovering lost commits/files. Next, you will discover how you can force rebase on some branches and use regular Git merge on other branches. You will also learn how to extract information from the repository.

As you progress through this book, you will learn how you can automate the usual Git processes by utilizing the hook system built into Git. The book also covers advanced repository management, including different options to rewrite the history of a Git repository. Finally, you will discover how you can work offline with Git, how to track what is going on behind the scenes, and how to use the stash for different purposes.

Approach

This practical guide contains a wide variety of recipes, taking you through all the topics you need to know about to fully utilize the most advanced features of the Git system.

Who this book is for

If you are a software developer or a build and release engineer who uses Git in your daily work and want to take your Git knowledge to the next level, then this book is for you. To understand and follow the recipes included in this book, basic knowledge of Git command-line code is mandatory.

Table of Contents

  1. Git Version Control Cookbook
    1. Table of Contents
    2. Git Version Control Cookbook
    3. Credits
    4. About the Authors
    5. About the Reviewers
    6. www.PacktPub.com
      1. Support files, eBooks, discount offers, and more
        1. Why Subscribe?
        2. Free Access for Packt account holders
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    8. 1. Navigating Git
      1. Introduction
      2. Git's objects
        1. Getting ready
        2. How to do it...
          1. The commit object
          2. The tree object
          3. The blob object
          4. The branch
          5. The tag object
        3. How it works...
        4. There's more...
        5. See also
      3. The three stages
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. See also
      4. Viewing the DAG
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      5. Extracting fixed issues
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      6. Getting a list of the changed files
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      7. Viewing history with Gitk
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      8. Finding commits in history
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      9. Searching through history code
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
    9. 2. Configuration
      1. Configuration targets
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      2. Querying the existing configuration
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      3. Templates
        1. Getting ready
        2. How to do it...
        3. How it works...
      4. A .git directory template
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      5. A few configuration examples
        1. Getting ready
        2. How to do it...
          1. Rebase and merge setup
          2. Expiry of objects
          3. Autocorrect
        3. How it works...
        4. There's more...
      6. Git aliases
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      7. The refspec exemplified
        1. Getting ready
        2. How to do it...
        3. How it works...
    10. 3. Branching, Merging, and Options
      1. Introduction
      2. Managing your local branches
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more...
      3. Branches with remotes
        1. Getting ready
        2. How to do it…
        3. There's more...
      4. Forcing a merge commit
        1. Getting ready
        2. How to do it...
        3. There's more…
      5. Using git rerere to merge known conflicts
        1. How to do it…
        2. There's more...
      6. The difference between branches
        1. Getting ready
        2. How to do it…
        3. There's more…
    11. 4. Rebase Regularly and Interactively, and Other Use Cases
      1. Introduction
      2. Rebasing commits to another branch
        1. Getting ready
        2. How to do it…
        3. How it works
      3. Continuing a rebase with merge conflicts
        1. How to do it
        2. How it works
        3. There's more…
      4. Rebasing selective commits interactively
        1. Getting ready
        2. How to do it
        3. There's more…
      5. Squashing commits using an interactive rebase
        1. Getting ready
        2. How to do it...
        3. There's more…
      6. Changing the author of commits using a rebase
        1. Getting ready
        2. How to do it...
        3. How it works...
      7. Auto-squashing commits
        1. Getting ready
        2. How to do it...
        3. There's more…
    12. 5. Storing Additional Information in Your Repository
      1. Introduction
      2. Adding your first Git note
        1. Getting ready
        2. How to do it…
        3. There's more...
      3. Separating notes by category
        1. Getting ready
        2. How to do it...
        3. How it works...
      4. Retrieving notes from the remote repository
        1. Getting ready
        2. How to do it...
        3. How it works...
      5. Pushing notes to a remote repository
        1. How to do it...
        2. There's more...
      6. Tagging commits in the repository
        1. Getting ready
        2. How to do it...
        3. There's more...
    13. 6. Extracting Data from the Repository
      1. Introduction
      2. Extracting the top contributor
        1. Getting ready
        2. How to do it...
        3. There's more...
      3. Finding bottlenecks in the source tree
        1. Getting ready
        2. How to do it...
        3. There's more...
      4. Grepping the commit messages
        1. Getting ready
        2. How to do it...
      5. The contents of the releases
        1. How to do it...
        2. How it works...
    14. 7. Enhancing Your Daily Work with Git Hooks, Aliases, and Scripts
      1. Introduction
      2. Using a branch description in the commit message
        1. Getting ready
        2. How to do it...
      3. Creating a dynamic commit message template
        1. Getting ready
        2. How to do it...
        3. There's more...
      4. Using external information in the commit message
        1. Getting ready
        2. How to do it...
      5. Preventing the push of specific commits
        1. Getting ready
        2. How to do it...
        3. There's more...
      6. Configuring and using Git aliases
        1. How to do it...
        2. How it works...
      7. Configuring and using Git scripts
        1. How to do it...
      8. Setting up and using a commit template
        1. Getting ready
        2. How to do it...
    15. 8. Recovering from Mistakes
      1. Introduction
      2. Undo – remove a commit completely
        1. Getting ready
        2. How to do it...
        3. How it works…
      3. Undo – remove a commit and retain the changes to files
        1. Getting ready
        2. How to do it...
        3. How it works…
      4. Undo – remove a commit and retain the changes in the staging area
        1. Getting ready
        2. How to do it...
        3. How it works…
      5. Undo – working with a dirty area
        1. Getting ready
        2. How to do it...
        3. How it works…
        4. See also
      6. Redo – recreate the latest commit with new changes
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There is more…
      7. Revert – undo the changes introduced by a commit
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      8. Reverting a merge
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There is more...
        5. See also
      9. Viewing past Git actions with git reflog
        1. Getting ready
        2. How to do it...
        3. How it works...
      10. Finding lost changes with git fsck
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
    16. 9. Repository Maintenance
      1. Introduction
      2. Pruning remote branches
        1. Getting ready
        2. How to do it...
        3. How it works…
        4. There's more…
      3. Running garbage collection manually
        1. Getting ready
        2. How to do it...
        3. How it works…
      4. Turning off automatic garbage collection
        1. Getting ready
        2. How to do it...
      5. Splitting a repository
        1. Getting ready
        2. How to do it...
        3. How it works…
        4. There's more…
      6. Rewriting history – changing a single file
        1. Getting ready
        2. How to do it...
        3. How it works…
      7. Back up your repositories as mirror repositories
        1. Getting ready
        2. How to do it...
        3. How it works…
        4. There's more…
      8. A quick submodule how-to
        1. Getting ready
        2. How to do it...
        3. There's more…
      9. Subtree merging
        1. Getting ready
        2. How to do it...
        3. How it works…
        4. See also
      10. Submodule versus subtree merging
    17. 10. Patching and Offline Sharing
      1. Introduction
      2. Creating patches
        1. Getting ready
        2. How to do it...
        3. How it works…
        4. There's more…
      3. Creating patches from branches
        1. Getting ready
        2. How to do it...
        3. How it works…
        4. There's more…
      4. Applying patches
        1. Getting ready
        2. How to do it...
        3. How it works…
        4. There's more…
      5. Sending patches
        1. Getting ready
        2. How to do it...
        3. How it works…
        4. There's more…
      6. Creating Git bundles
        1. Getting ready
        2. How to do it...
        3. How it works…
      7. Using a Git bundle
        1. Getting ready
        2. How to do it…
        3. There's more…
      8. Creating archives from a tree
        1. Getting ready
        2. How to do it...
        3. There's more…
    18. 11. Git Plumbing and Attributes
      1. Introduction
      2. Displaying the repository information
        1. Getting ready
        2. How to do it...
        3. There's more…
      3. Displaying the tree information
        1. Getting ready
        2. How to do it...
      4. Displaying the file information
        1. Getting ready
        2. How to do it...
        3. There's more…
      5. Writing a blob object to the database
        1. Getting ready
        2. How to do it...
        3. How it works…
        4. There's more…
      6. Writing a tree object to the database
        1. Getting ready
        2. How to do it...
        3. How it works…
      7. Writing a commit object to the database
        1. Getting ready
        2. How to do it...
        3. How it works…
      8. Keyword expansion with attribute filters
        1. Getting ready
        2. How to do it...
        3. How it works…
        4. There's more…
      9. Metadata diff of binary files
        1. Getting ready
        2. How to do it...
        3. How it works…
        4. There's more…
      10. Storing binaries elsewhere
        1. Getting ready
        2. How to do it...
        3. How it works…
        4. There's more…
        5. See also
      11. Checking the attributes of a file
        1. Getting ready
        2. How to do it...
      12. Attributes to export an archive
        1. Getting ready
        2. How to do it...
        3. There's more…
    19. 12. Tips and Tricks
      1. Introduction
      2. Using git stash
        1. Getting ready
        2. How to do it...
        3. How it works…
        4. There's more…
      3. Saving and applying stashes
        1. Getting ready
        2. How to do it...
        3. There's more…
      4. Debugging with git bisect
        1. Getting ready
        2. How to do it...
        3. There's more…
      5. Using the blame command
        1. Getting ready
        2. How to do it...
        3. There's more…
      6. Color UI in the prompt
        1. Getting ready
        2. How to do it...
        3. There's more…
      7. Autocompletion
        1. Getting ready
          1. Linux
          2. Mac
          3. Windows
        2. How to do it...
        3. How it works…
        4. There's more…
      8. Bash prompt with status information
        1. Getting ready
        2. How to do it...
        3. How it works…
        4. There's more…
        5. See also
      9. More aliases
        1. Getting ready
        2. How to do it...
      10. Interactive add
        1. Getting ready
        2. How to do it...
        3. There's more…
      11. Interactive add with Git GUI
        1. Getting ready
        2. How to do it...
      12. Ignoring files
        1. Getting ready
        2. How to do it...
        3. There's more…
        4. See also…
      13. Showing and cleaning ignored files
        1. Getting ready
        2. How to do it...
        3. There's more…
    20. Index