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 bugpr-1, calling the new branchbug/pr-1.The same developer adds the line “Fix Problem report 1” to a file in the
bug/pr-1branch.Meanwhile, another developer fixes bug
pr-3in themasterbranch, adding the line “Fix Problem report 3” to the same file in themasterbranch.
In short, one line was added to a file in each branch. If you look ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access