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:
Someone creates a new branch off the
masterbranch to fix bug
pr-1, calling the new branch
The same developer adds the line “Fix Problem report 1” to a file in the
Meanwhile, another developer fixes bug
masterbranch, adding the line “Fix Problem report 3” to the same file in the
In short, one line was added to a file in each branch. If you look ...