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
master
branch 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-1
branch.Meanwhile, another developer fixes bug
pr-3
in themaster
branch, adding the line âFix Problem report 3â to the same file in themaster
branch.
In short, one line was added to a file in each branch. ...
Get Version Control with Git now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.