2

When I want to find the commits that are in branch A but not in branch B I often write

git log A ^ B

But according to the SO post How do I see the commit differences between branches in git? the following does the same thing:

git log B..A

Are these commands identical? What is the difference?

Community
  • 1
  • 1
quant
  • 21,507
  • 32
  • 115
  • 211

1 Answers1

3

From the official documentation for git log covering History Simplification we find:

--ancestry-path
When given a range of commits to display (e.g. commit1..commit2 or commit2 ^commit1), only display commits that exist directly on the ancestry chain between the commit1 and commit2, i.e. commits that are both descendants of commit1, and ancestors of commit2.

It seems from the documentation itself that either git log ^ B and git log A..B behave identically, and the ^ and .. operators can be used interchangeably with git log.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • They are different operators, just in this case they gave the same result. E.g. You could have multiple `^commit-ish` in one line – Alexey Ten Oct 23 '15 at 05:28
  • @Alexey Yes, my answer specifically says that these operators are interchangeable in the case of `git log`. – Tim Biegeleisen Oct 23 '15 at 05:29
  • 1
    On a side note: It would be more accurate to consider `A..B` a shorthand of `A ^B`, since the `^` operator can be used for more complex ref specs. Such a spec could simply take the form of `A ^B ^C`. – Sascha Wolf Oct 23 '15 at 12:15