Repository: jesseduffield/lazygit (language: go)

Issue:
Interactive rebasing doesn't show 'blue' commit 
**Describe the bug**
Whenever I press 'e' on a commit all the above commit disappear making it impossible to rebase. 
I tried with the default config, on a repo started with 'git init'.
log says "Jun 26 21:44:24 |ERRO| fatal: HEAD does not point to a branch"


**To Reproduce**
Steps to reproduce the behavior:

1. Go to the commit section
2. Click on 'e' to start rebasing
3. All the above commit disappear so I can't pick, squash etc

**Expected behavior**
The commits above the rebasing point should turn blue and let me interact with them.

**Screenshots**
before pressing 'e'
![Screenshot from 2023-06-26 21-31-59](https://github.com/jesseduffield/lazygit/assets/38473290/c97373ed-e86f-46ba-8746-c9157ef35591)
after pressing 'e'
![Screenshot from 2023-06-26 21-32-07](https://github.com/jesseduffield/lazygit/assets/38473290/601b42c1-ad0d-4dec-be42-8095eb2ac5e8)



**Version info:**
lazygit version : 0.38.2        git version : 2.25.1
lazygit --version =>
commit=5149b24ab3dfad3860e2300519c7c583dcc8c9ff, build date=2023-05-03T08:00:22Z, build source=binaryRelease, version=0.38.2, os=linux, arch=amd64, git version=2.25.1
git --version =>
git version 2.25.1

**Log after pressing 'e'**

Jun 26 21:44:24 |INFO| RunCommand command="Beginning interactive rebase at 'bff05f343079b795d19658d1d2303b9a259cfbb8'"
Jun 26 21:44:24 |DEBU| RunCommand command="git rebase --interactive --autostash --keep-empty --no-autosquash --rebase-merges bff05f343079b795d19658d1d2303b9a259cfbb8"
Jun 26 21:44:24 |DEBU| RunCommand
Jun 26 21:44:24 |INFO| language: en
Jun 26 21:44:24 |INFO| Lazygit invoked as interactive rebase demon
Jun 26 21:44:24 |INFO| args: [/usr/local/bin/lazygit /home/anon/Documents/Code/testLazygit/.git/rebase-merge/git-rebase-todo]
Jun 26 21:44:24 |INFO| refreshing all scopes in async mode
Jun 26 21:44:24 |DEBU| RunCommand command="git stash list -z --pretty='%gs'"
Jun 26 21:44:24 |DEBU| RunCommand command="git tag --list -n --sort=-creatordate"
Jun 26 21:44:24 |DEBU| using cache for key status.showUntrackedFiles
Jun 26 21:44:24 |DEBU| RunCommand command="git status --untracked-files=all --porcelain -z"
Jun 26 21:44:24 |DEBU| RunCommand command="git branch -r"
Jun 26 21:44:24 |DEBU| RunCommand command="git merge-base \"HEAD\" \"HEAD\"@{u}"
Jun 26 21:44:24 |ERRO| fatal: HEAD does not point to a branch

Jun 26 21:44:24 |DEBU| RunCommand command="git for-each-ref --sort=-committerdate --format=\"%(HEAD)%00%(refname:short)%00%(upstream:short)%00%(upstream:track)\" refs/heads"
Jun 26 21:44:24 |DEBU| RunCommand command="git symbolic-ref --short HEAD"
Jun 26 21:44:24 |DEBU| RunCommand
Jun 26 21:44:24 |ERRO| fatal: ref HEAD is not a symbolic ref

Jun 26 21:44:24 |ERRO| fatal: ref HEAD is not a symbolic ref

Jun 26 21:44:24 |DEBU| RunCommand command="git branch --points-at=HEAD --format=\"%(HEAD)%00%(objectname)%00%(refname)\""
Jun 26 21:44:24 |DEBU| RunCommand
Jun 26 21:44:24 |DEBU| RunCommand command="git merge-base \"HEAD\" \"master\""
Jun 26 21:44:24 |DEBU| RunCommand command="git show --submodule --color=always --unified=3 --stat -p f8704c251a5d40afab8a46bed1f91b50e9afae66"




Discussion / hints:
The two fatal errors in the log are red herrings, those are normal. (It would be nice if we could find a way to avoid logging these, it's misleading and confusing.)

It looks like lazygit has problems parsing the git-rebase-todo file. Could you post the contents of your `.git/rebase-merge/git-rebase-todo` file after pressing `e`?
Never mind, I found the error. It's caused by the pretty old git version you are using. I'll try to come up with a fix, but it might take me a few days; in the meantime, if it's an option for you to update git to the latest version, that will fix the problem.
I confirm updating git fixed the problem, thanks !
My git version was the latest using apt for ubuntu 20.04 so maybe other people might encounter that problem too.
Thanks for confirming.

Meanwhile I bisected and found that the very next version from yours (2.25.2, you were on 2.25.1) fixes the problem...

It will be easy enough for lazygit to work around the problem. I'll work on this soon.

Fix patch:
diff --git a/pkg/commands/git_commands/commit_loader.go b/pkg/commands/git_commands/commit_loader.go
index 148c96776a9..32d470fc808 100644
--- a/pkg/commands/git_commands/commit_loader.go
+++ b/pkg/commands/git_commands/commit_loader.go
@@ -222,11 +222,24 @@ func (self *CommitLoader) getHydratedRebasingCommits(rebaseMode enums.RebaseMode
 		return nil, err
 	}
 
+	findFullCommit := lo.Ternary(self.version.IsOlderThan(2, 25, 2),
+		func(sha string) *models.Commit {
+			for s, c := range fullCommits {
+				if strings.HasPrefix(s, sha) {
+					return c
+				}
+			}
+			return nil
+		},
+		func(sha string) *models.Commit {
+			return fullCommits[sha]
+		})
+
 	hydratedCommits := make([]*models.Commit, 0, len(commits))
 	for _, rebasingCommit := range commits {
 		if rebasingCommit.Sha == "" {
 			hydratedCommits = append(hydratedCommits, rebasingCommit)
-		} else if commit := fullCommits[rebasingCommit.Sha]; commit != nil {
+		} else if commit := findFullCommit(rebasingCommit.Sha); commit != nil {
 			commit.Action = rebasingCommit.Action
 			commit.Status = rebasingCommit.Status
 			hydratedCommits = append(hydratedCommits, commit)


Test patch: