Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Mastering Git
Mastering Git

Mastering Git: Attain expert level proficiency with Git for enhanced productivity and efficient collaboration

eBook
$29.99 $43.99
Paperback
$54.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Table of content icon View table of contents Preview book icon Preview Book

Mastering Git

Chapter 2. Exploring Project History

One of the most important parts of mastering a version control system is exploring project history, making use of the fact that with version control systems we have an archive of every version that has ever existed. Here, the reader will learn how to select, filter, and view the range of revisions; how to refer to the revisions (revision selection); and how to find revisions using different criteria.

This chapter will introduce the concept of Directed Acyclic Graph (DAG) of revisions and explain how this concept relates to the ideas of branches, tags, and of the current branch in Git.

Here is the list of topics we will cover in this chapter:

  • Revision selection
  • Revision range selection, limiting history, history simplification
  • Searching history with "pickaxe" tool and diff search
  • Finding bugs with git bisect
  • Line-wise history of file contents with git blame, and rename detection
  • Selecting and formatting output (the pretty formats)
  • Summarizing...

Directed Acyclic Graphs

What makes version control systems different from backup applications is, among others, the ability to represent more than linear history. This is necessary, both to support the simultaneous parallel development by different developers (each developer in his or her own clone of repository), and to allow independent parallel lines of development—branches. For example, one might want to keep the ongoing development and work on bug fixes for the stable version isolated; this is possible by using individual branches for the separate lines of development. Version control system (VCS) thus needs to be able to model such a (non-linear) way of development and to have some structure to represent multiple revisions.

Directed Acyclic Graphs

Fig 1. A generic example of the Directed Acyclic Graph (DAG). The same graph is represented on both sides: in free-form on the left, left-to-right order on the right.

The structure that Git uses (on the abstract level) to represent the possible non-linear...

Single revision selection

During development, many times you want to select a single revision in the history of a project, to examine it, or to compare with the current version. The ability to a select revision is also the basis for selecting a revision range, for example a subsection of history to examine.

Many Git commands take revision parameters as arguments, which is typically denoted by <rev> in Git reference documentation. Git allows you to specify specific commits or a range of commits in several ways.

HEAD – the implicit revision

Most, but not all, Git commands that require the revision parameter, default to using HEAD. For example, git log and git log HEAD will show the same information.

The HEAD denotes the current branch, or in other words the commit that was checked out into the working directory, and forms a base of a current work.

There are a few other references which are similar to HEAD:

  • FETCH_HEAD: This records the information about the remote branches that were...

Selecting the revision range

Now that you can specify individual revisions in multiple ways, let's see how to specify ranges of revisions, a subset of the DAG we want to examine. Revision ranges are particularly useful for viewing selected parts of history of a project.

For example, you can use range specifications to answer questions such as, "What work is on this branch that I haven't yet merged into my main branch?" and "What work is on my main branch I haven't yet published?", or simply "What was done on this branch since its creation?".

Single revision as a revision range

History traversing commands such as git log operate on a set of commits, walking down a chain of revisions from child to parent. These kind of commands, given a single revision as an argument (as described in the Single revision selection section of this chapter), will show the set of commits reachable from that revision, following the commit ancestry chain, all the way down...

Searching history

A huge number and variety of useful options to the git log command are limiting options—that is, options that let you show only a subset of commits. This complements selecting commits to view by passing the appropriate revision range, and allows us to search the history for the specific versions, utilizing information other than the shape of the DAG of revisions.

Limiting the number of revisions

The most basic way of limiting the git log output, the simplest limiting option, is to show only then most recent commits. This is done using the -<n> option (where n is any integer); this can be also written as -n <n>, or in long form as --max-count=<n>. For example, git log -2 would show the two last (most recent) commits in the current line of development, starting from the implicit HEAD revision.

You can skip the first few commits shown with --skip=<n>.

Matching revision metadata

History limiting options can be divided into those that check information...

History of a file

As described in the Whole-tree commits section at the beginning of this chapter, in Git revisions are about the state of the whole project as one single entity.

In many cases, especially with larger projects, we are interested only in the history of a single file, or in the history limited to the changes in the given directory (in the given subsystem).

Path limiting

To examine the history of a single file, you can simply use use git log <pathname>. Git will then only show all those revisions that affected the pathname (a file or a directory) given, which means those revisions where there was a change to the given file, or a change to a file inside the given subdirectory.

Tip

Disambiguation between branch names and path names

Git usually guesses what you meant by writing git log foo; did you meant to ask for the history of branch foo (line of development), or for the history of the file foo. However, sometimes Git can get confused. To prevent confusion between pathnames...

Directed Acyclic Graphs


What makes version control systems different from backup applications is, among others, the ability to represent more than linear history. This is necessary, both to support the simultaneous parallel development by different developers (each developer in his or her own clone of repository), and to allow independent parallel lines of development—branches. For example, one might want to keep the ongoing development and work on bug fixes for the stable version isolated; this is possible by using individual branches for the separate lines of development. Version control system (VCS) thus needs to be able to model such a (non-linear) way of development and to have some structure to represent multiple revisions.

Fig 1. A generic example of the Directed Acyclic Graph (DAG). The same graph is represented on both sides: in free-form on the left, left-to-right order on the right.

The structure that Git uses (on the abstract level) to represent the possible non-linear history...

Single revision selection


During development, many times you want to select a single revision in the history of a project, to examine it, or to compare with the current version. The ability to a select revision is also the basis for selecting a revision range, for example a subsection of history to examine.

Many Git commands take revision parameters as arguments, which is typically denoted by <rev> in Git reference documentation. Git allows you to specify specific commits or a range of commits in several ways.

HEAD – the implicit revision

Most, but not all, Git commands that require the revision parameter, default to using HEAD. For example, git log and git log HEAD will show the same information.

The HEAD denotes the current branch, or in other words the commit that was checked out into the working directory, and forms a base of a current work.

There are a few other references which are similar to HEAD:

  • FETCH_HEAD: This records the information about the remote branches that were fetched...

Selecting the revision range


Now that you can specify individual revisions in multiple ways, let's see how to specify ranges of revisions, a subset of the DAG we want to examine. Revision ranges are particularly useful for viewing selected parts of history of a project.

For example, you can use range specifications to answer questions such as, "What work is on this branch that I haven't yet merged into my main branch?" and "What work is on my main branch I haven't yet published?", or simply "What was done on this branch since its creation?".

Single revision as a revision range

History traversing commands such as git log operate on a set of commits, walking down a chain of revisions from child to parent. These kind of commands, given a single revision as an argument (as described in the Single revision selection section of this chapter), will show the set of commits reachable from that revision, following the commit ancestry chain, all the way down to the root commits.

For example, git log master...

Left arrow icon Right arrow icon

Key benefits

  • Set up Git for solo and collaborative development
  • Harness the full power of Git version control system to customize Git behavior, manipulate history, integrate external tools and explore platform shortcuts
  • A detailed guide, which explains how to apply advanced Git techniques and workflows and ways to handle submodules

Description

Git is one of the most popular types of Source Code Management (SCM) and Distributed Version Control System (DVCS). Despite the powerful and versatile nature of the tool enveloping strong support for nonlinear development and the ability to handle large projects efficiently, it is a complex tool and often regarded as “user-unfriendly”. Getting to know the ideas and concepts behind the architecture of Git will help you make full use of its power and understand its behavior. Learning the best practices and recommended workflows should help you to avoid problems and ensure trouble-free development. The book scope is meticulously designed to help you gain deeper insights into Git's architecture, its underlying concepts, behavior, and best practices. Mastering Git starts with a quick implementation example of using Git for a collaborative development of a sample project to establish the foundation knowledge of Git operational tasks and concepts. Furthermore, as you progress through the book, the tutorials provide detailed descriptions of various areas of usage: from archaeology, through managing your own work, to working with other developers. This book also helps augment your understanding to examine and explore project history, create and manage your contributions, set up repositories and branches for collaboration in centralized and distributed version control, integrate work from other developers, customize and extend Git, and recover from repository errors. By exploring advanced Git practices, you will attain a deeper understanding of Git’s behavior, allowing you to customize and extend existing recipes and write your own.

Who is this book for?

If you are a Git user with reasonable knowledge of Git and familiarity with basic concepts such as branching, merging, staging, and workflows, this is the book for you. Basic knowledge of installing Git and software configuration management concepts is essential.

What you will learn

  • Explore project history, find revisions using different criteria, and filter and format how history looks
  • Manage your working directory and staging area for commits and interactively create new revisions and amend them
  • Set up repositories and branches for collaboration
  • Submit your own contributions and integrate contributions from other developers via merging or rebasing
  • Customize Git behavior system-wide, on a per-user, per-repository, and per-file basis
  • Take up the administration and set up of Git repositories, configure access, find and recover from repository errors, and perform repository maintenance
  • Chose a workflow and configure and set up support for the chosen workflow

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Apr 21, 2016
Length: 418 pages
Edition : 1st
Language : English
ISBN-13 : 9781783553761
Category :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want

Product Details

Publication date : Apr 21, 2016
Length: 418 pages
Edition : 1st
Language : English
ISBN-13 : 9781783553761
Category :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 133.97
Mastering Git
$54.99
Git Version Control Cookbook
$48.99
Git Best Practices Guide
$29.99
Total $ 133.97 Stars icon

Table of Contents

13 Chapters
1. Git Basics in Practice Chevron down icon Chevron up icon
2. Exploring Project History Chevron down icon Chevron up icon
3. Developing with Git Chevron down icon Chevron up icon
4. Managing Your Worktree Chevron down icon Chevron up icon
5. Collaborative Development with Git Chevron down icon Chevron up icon
6. Advanced Branching Techniques Chevron down icon Chevron up icon
7. Merging Changes Together Chevron down icon Chevron up icon
8. Keeping History Clean Chevron down icon Chevron up icon
9. Managing Subprojects – Building a Living Framework Chevron down icon Chevron up icon
10. Customizing and Extending Git Chevron down icon Chevron up icon
11. Git Administration Chevron down icon Chevron up icon
12. Git Best Practices Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.5
(2 Ratings)
5 star 0%
4 star 50%
3 star 50%
2 star 0%
1 star 0%
Michael Lynch Jun 15, 2017
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
This is a great book about git, the command line tool, and service. It talks about generic git (as opposed to GitHub/Bitbucket specific features.) I really like that it does talk just about git, everything in the book should work on any operating system, and it is everything every developer needs to know to use git daily (and some fun things like prompts and alias' are also covered.)The only thing keeping this from 5 stars is printing more sample output in the book. It is hands on, but if you are reading w/o a computer in front of you, it can be hard to follow. My advice is to just read the book with an open terminal.
Amazon Verified review Amazon
Just Some Guy Jun 17, 2022
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
First, this book IS NOT, AT ALL, for someone new to Git. If you're trying to learn Git, or even if you know Git but want to get better, look elsewhere. This book is really only appropriate for serious engineers or DevOps folks who _already_ have complete confidence using Git _exclusively_ via the terminal CLI, and want to get even deeper into the weeds.Second, unfortunately it's just not a great book. It IS packed with TONS of great information, but it is just a completely _miserable_ read.Yes, that's a very harsh judgement. Here are my top complaints:A) The editing is terrible (like far too many Packt books). There are blatant grammatical and linguistic errors sprinkled throughout the book, and they are a constant distraction which interferes with comprehension.B) The signal/noise ratio is terrible. The author rambles on and on, and just needs to get to the point! There is actually TONS of great information in this book (for the _serious_ Git pro), but it's buried in just mountains of noise. Far too often it reads like a stream of consciousness; The entire book is stuffed with long rambling parentheticals/asides, random one-off hypotheticals, etc. If these built around a common core narrative or working demo project it might hold together, but they don't. Thus, you just have to parse endless words to get to the value.C) The author is just not a very good teacher or writer. It's really too bad, because he is clearly a Git demigod - I mean, he knows it inside out, and really does share as much of that knowledge as he can. But the way he writes just goes on and on, and it ends up being confusing and distracting to the point of agony (the diagrams are confusing too, btw).D) The order of chapters itself is confusing. If you do read this book, skip past chapter 2 and come back to it later. It will make a lot more sense later on. Just trust me.E) Layout Rant: In a book or article, a callout or pull-quote is a device used to bring emphasis and attention to a very short block of text (1 - 3 sentences, ideally). When you have an _entire_ multi-paragraph page of text formatted that way, it is no longer a callout; it's a section or subtopic. Format it that way (and rein in your author while you're at it, pleeeeease).I fly through complex tech books on a regular basis - and this is the first time I remember actually getting _mad_ while reading one. I was mad because this book has so much great info that I decided I _had_ to keep reading it, but it took an excruciating amount of patience and focus to get through the noise and make sense of the meandering confusing explanations. Usually it's pretty easy to determine a tech book isn't great, and which point I just flip through and move on - but this one made me slog through the mud for hours. I was not happy about it.Final word: If you are a _serious_ Git user who wants to pick up a ton of great new _tactical_ detail and knowledge, this is a great book for you. If you're someone new to Git, or even fairly advanced but not needing to manage complex projects or deal with deep and complicated repo management issues, I'd say you should look elsewhere. This book definitely has things to teach you, but you’ll never need most of it, and your time and money will be better spent on something less advanced and better written.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.