Why does the number of commits shown in a git log not match with the number of commits in a git rebase -i HEAD~n?

I want to perform an interactive rebase in order to squash some commits.

The way I do this is:

  • use git log to search for the commits I want to squash
  • count the number of commits from HEAD
  • use git rebase -i HEAD~n where n is the number of commits from HEAD

Is this the wrong method? I have been using this technique for a while and sometimes wondered why the number of commits doesn’t match up.

To demonstrate, here is the output from git log --pretty=format:"%h%x09%an%x09%ad%x09%s".

130f00e me              Fri Apr 19 16:37:15 2024 +0000  commit message
c7bb70c me on github    Fri Apr 19 17:08:28 2024 +0100  Merge pull request #419 from company/MY-DEV-BRANCH
3e3f411 me              Fri Apr 19 16:07:42 2024 +0000  commit message
47e769e colleague       Fri Apr 19 17:00:26 2024 +0100  Merge pull request #418 from company/colleague -patch-28
998be63 colleague       Fri Apr 19 16:59:53 2024 +0100  commit message
7b75da8 colleague       Fri Apr 19 16:59:31 2024 +0100  commit message
c7f0da1 colleague       Fri Apr 19 15:54:59 2024 +0100  Merge pull request #417 from company/mycolleague/HIS-DEV_BRANCH
43e927d colleague       Fri Apr 19 15:54:49 2024 +0100  Merge branch 'master' into mycolleague/HIS-DEV_BRANCH
06d62f2 colleague       Fri Apr 19 14:52:50 2024 +0000  commit message
3de4d90 me on github    Fri Apr 19 15:08:37 2024 +0100  Merge pull request #414 from company/MY-DEV-BRANCH
374add4 me              Fri Apr 19 14:00:36 2024 +0000  commit message
ba4fd3b me              Fri Apr 19 14:00:07 2024 +0000  Merge remote-tracking branch 'origin/master' into MY-DEV-BRANCH
aed07ae me              Fri Apr 19 13:37:31 2024 +0000  commit message
44e119d colleague       Fri Apr 19 10:09:46 2024 +0100  Merge pull request #416 from company/colleague -patch-46
da11abe colleague       Fri Apr 19 10:09:39 2024 +0100  commit message
a74b81a colleague       Fri Apr 19 10:09:18 2024 +0100  commit message
80b4003 colleague       Fri Apr 19 09:51:56 2024 +0100  Merge pull request #415 from company/mycolleague/HIS-DEV_BRANCH
0489446 colleague       Fri Apr 19 08:50:09 2024 +0000  commit message

There are 18 lines in this output. Therefore n=18.

Here is the output from git rebase -i HEAD~18.

pick 45c0d75 (me <[email protected]>) commit message
pick a519421 (me <[email protected]>) commit message
pick 5bb52cc (me <[email protected]>) commit message
pick 51f831a (me <[email protected]>) commit message
pick 530a6f3 (me <[email protected]>) commit message
pick 72c89c8 (me <[email protected]>) commit message
pick 59052f4 (me <[email protected]>) commit message
pick ce9faf9 (colleague <[email protected]>) commit message
pick e399c0a (colleague <[email protected]>) commit message
pick 82f29f0 (colleague <[email protected]>) commit message
pick 9c405ed (colleague <[email protected]>) commit message
pick a1f4893 (colleague <[email protected]>) commit message
pick b974516 (colleague <[email protected]>) commit message
pick 50d2394 (colleague <[email protected]>) commit message
pick 020e80c (colleague <[email protected]>) commit message
pick 09addd8 (colleague <[email protected]>) commit message
pick ef65821 (colleague <[email protected]>) commit message
pick ca4f3f7 (colleague <[email protected]>) commit message
pick e1098a7 (colleague <[email protected]>) commit message
pick 2275c59 (colleague <[email protected]>) commit message
pick c3614f2 (other-colleague <[email protected]>) commit message
pick 0e7fa78 (other-colleague <[email protected]>) commit message
pick b7ee582 (me <[email protected]>) commit message
pick 117178a (colleague <[email protected]>) commit message
pick 4f68792 (me <[email protected]>) commit message
pick 821a479 (me <[email protected]>) commit message
pick 6ea09f1 (me <[email protected]>) commit message
pick 0936af5 (me <[email protected]>) commit message
pick 6b43a34 (me <[email protected]>) commit message
pick 23a1f3e (me <[email protected]>) commit message
pick 9e907af (colleague <[email protected]>) commit message
pick 64c08cc (colleague <[email protected]>) commit message
pick 58e0601 (colleague <[email protected]>) commit message
pick 002c5e6 (colleague <[email protected]>) commit message
pick 17f71cb (colleague <[email protected]>) commit message
pick de2b3a6 (colleague <[email protected]>) commit message
pick 9a2bfb0 (colleague <[email protected]>) commit message
pick 94728d9 (colleague <[email protected]>) commit message # empty
pick 48f1190 (colleague <[email protected]>) commit message
pick 0489446 (colleague <[email protected]>) commit message
pick 06d62f2 (colleague <[email protected]>) commit message
pick 392e9c3 (me <[email protected]>) commit message
pick aed07ae (me <[email protected]>) commit message
pick a74b81a (colleague <[email protected]>) commit message
pick da11abe (colleague <[email protected]>) commit message
pick 374add4 (me <[email protected]>) commit message
pick 7b75da8 (colleague <[email protected]>) commit message
pick 998be63 (colleague <[email protected]>) commit message
pick 3e3f411 (me <[email protected]>) commit message
pick 130f00e (me <[email protected]>) commit message

# Rebase d0bea91..130f00e onto d0bea91 (50 commands)

This is clearly a lot more than 18 lines. In fact, it is a total of 50 lines.

Why does this happen? What is going on here? Clearly this method of rebasing doesn’t make much sense. So what should I be doing instead?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật