O'Reilly logo

Version Control with Git by Jon Loeliger

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

git diff and Commit Ranges

There are two additional forms of git diff that bear some explanation, especially in contrast to git log.

The git diff command supports a double-dot syntax to represent the difference between two commits. Thus, the following two commands are equivalent:

git diff master bug/pr-1
git diff master..bug/pr-1

Unfortunately, the double-dot syntax in git diff means something quite different from the same syntax in git log, which you learned about in Chapter 6. It’s worth comparing git diff and git log because doing so highlights the relationships of these two commands to changes made in repositories. Some points to keep in mind for the following example:

  • git diff doesn’t care about the history of the files it compares or anything about branches.

  • git log is extremely conscious of how one file changed to become another—say, when two branches diverged and what happened on each branch.

The log and diff commands perform two fundamentally different operations. Whereas log operates on a set of commits, diff operates on two different endpoints.

Imagine the following sequence of events:

  1. Someone creates a new branch off the master branch to fix bug pr-1, calling the new branch bug/pr-1.

  2. The same developer adds the line Fix Problem report 1 to a file in the bug/pr-1 branch.

  3. Meanwhile, another developer fixes bug pr-3 in the master branch, adding the line Fix Problem report 3 to the same file in the master branch.

In short, one line was added to a file in each branch. If you look ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required