Is there a quick way to “git diff” from the point or branch origin?

后端 未结 7 1191
北恋
北恋 2020-12-23 11:21

I have looked at various SO answers on using git diff and git revisions (HEAD, ORIG_HEAD, FETCH_HEAD, etc.) and I still haven\'t found an easy way to list the c

7条回答
  •  梦毁少年i
    2020-12-23 11:52

    For diffs, you want the three-dot notation. If your branch is called dev and it branched from master:

    % git diff master...dev
    

    For log, you want the two-dot notation:

    % git log master..dev
    

    The revision syntax r1..r2 (with two dots) means "everything reachable from r2 (inclusive) but not reachable from r1 (inclusive)". The normal way to use this is to think of r1 and r2 as specifying a range in a sequence of commits (r1 exclusive, r2 inclusive), so if you have 10 revisions, 3..7 will show you changes 4, 5, 6, and 7. It's {1, 2, 3, 4, 5, 6, 7} minus {1, 2, 3}. But r1 doesn't necessarily have to be an ancestor of r2. Think of it more like a set operation where r1 represents the entire ancestry from r1 backwards, and r2 represents the entire ancestry from r2 backwards, and you're subtracting the first set from the second set.

    So then:

    git log master..dev
    

    is the entire history of the branch minus the entire history of master. In other words, just the branch.

提交回复
热议问题