0

I have a reasonably tidy Git history, with feature branches merging into the main branch. This can be seen in the results to git log --graph --oneline:

*   f8b3a40 (HEAD -> main, upstream/main) Feature baz
|\  
| * 5044a90 baz2
| * fa0c768 baz1
|/  
*   5485e88 Feature bar
|\  
| * f10992d bar5
| * 72c6f1b bar4
| * 05f902b bar3
| * 3d32bb6 bar2
| * a8274c6 bar1
|/  
*   2449d02 Feature foo
|\  
| * 437e321 foo6
| * 5e7af85 foo5
| * 5babacb foo4
| * a66ec89 foo3

So I can get a nice summary with git log --first-parent --oneline:

f8b3a40 (HEAD -> main, upstream/main) Feature baz
5485e88 Feature bar
2449d02 Feature foo
7e68bab Feature fizzbuzz

Now I want to review the changes between foo and bar. git diff 5485e88..2449d02 works as expected, I can see all the code changes. But git log 5485e88..2449d02 is empty. I am expecting something like:

commit 5485e88
Author: Jimmy Weasel <jimmy@example.com>
Date:   Wed Mar 22 15:49:53 2023 +0000

Feature bar...

commit f10992d
Author: Jimmy Weasel <jimmy@example.com>
Date:   Wed Mar 22 15:25:03 2023 +0000

bar5...

commit 72c6f1b
Author: Jimmy Weasel <jimmy@example.com>
Date:   Wed Mar 22 15:22:01 2023 +0000

bar4...

How can I achieve that, given only the values from the --first-parent output?

lofidevops
  • 15,528
  • 14
  • 79
  • 119

2 Answers2

3

Note that the two-dot syntax of log is shorthand for the exclusion operator (^):

git log A..B
# is the same as
git log B ^A

In words that says:

Show me all commits reachable by B that aren't reachable by A.

When either A or B is a direct descendant of the other, then you'll end up excluding everything if you reverse them. This becomes more obvious when you say it out loud:

git log 5485e88..2449d02

Would be in words:

Show me all commits reachable by 2449d02 that are not reachable by 5485e88.

If you stare at your graph while saying that it'll be clear that's it's backwards.

Side Note: Diff with 2 dots is the same as diff with no dots:

git diff A B
# is the same as
git diff A..B

I find this summary to be helpful when thinking about 2 dots vs 3 dots, and how they are kind of opposite between log and diff.

TTT
  • 22,611
  • 8
  • 63
  • 69
2

The order is wrong. You are inadvertently asking for git log merge2..merge1.

If you instead enter git log 2449d02..5485e88 (FROM foo TO bar) you will get the commits AFTER "Feature foo" up to and including "Feature bar". Note that commit 2449d02 "Feature foo" will not appear.

lofidevops
  • 15,528
  • 14
  • 79
  • 119