Git –max-count-oldest without the –reverse Trap
Git --max-count-oldest without the --reverse Trap
Thesis
People often want the oldest N commits of a range. The folklore git log --reverse | head is fragile. Newer Git adds --max-count-oldest (Git 2.55+). This box has Git 2.47.3, so the new flag is documented as not run locally.
Mental model
good (Git ≥ 2.55): git log --max-count-oldest=5 main..HEAD
fragile: git log --reverse main..feature | head -5
Worked examples
git --version
git log -h 2>&1 | grep max-count-oldest || echo "flag not in this git"On this host: git version 2.47.3 — flag not present.
Trap
--reverse | head in scripts. Buffering and full walks make it a bad automation default.
Boring rule
Document the minimum Git version next to any script that uses --max-count-oldest.
Try this
- On Git 2.55+, compare timings on a long branch.
- Read the Git 2.55 release notes.
- Add a CI check for minimum
gitversion.
Sources
- Git 2.55 release notes /
git-log(1)