Skip to content

Preserved Commit Message not cleared when exiting git editor #4557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ChrisMcD1 opened this issue May 11, 2025 · 1 comment · May be fixed by #4558
Open

Preserved Commit Message not cleared when exiting git editor #4557

ChrisMcD1 opened this issue May 11, 2025 · 1 comment · May be fixed by #4558
Labels
bug Something isn't working

Comments

@ChrisMcD1
Copy link
Contributor

Describe the bug
I often find myself initiating a commit message with c, but then halfway through typing the message, realize that is is likely to be more substantial than I thought. I press <esc> and then C to launch my editor where I can edit a larger commit body more effectively. I finish my commit message, close my editor, return to LazyGit and all is well.

Unfortunately, the next time I press c, creating a totally new commit, my partially completed message is still present. It no longer is relevant, so I have to delete the few words I typed before.

To Reproduce
Steps to reproduce the behavior:

  1. Set $EDITOR equal to nvim
  2. Edit some files
  3. Stage files
  4. Press c
  5. Type "Hello World"
  6. Press <esc>
  7. Press C
  8. Type "Some commit message"
  9. Press :wq to save commit message and exit
  10. Press <enter> to return to lazygit
  11. Edit some more files
  12. Stage those files
  13. Press c
  14. See "Hello World" is still there

Expected behavior
I expect to see no preserved commit message.

Screenshots
N/A

Version info:
Building lazygit from master on 5d30409f338d1edef18054a9b3c051a5fd92a20d
git version 2.25.1
Running in windows WSL2, Ubuntu

Additional context
I plan to implement this feature myself, just creating this issue for posterity.
I originally had this as a feature request, but then saw that there was code here that I believe attempts to do this exact behavior, so I changed it to a bug report.

// We won't be able to tell whether the commit was successful, because
// RunSubprocessAndRefresh doesn't return the error (it opens an error alert
// itself and returns nil on error). But even if we could, we wouldn't have
// access to the last message that the user typed, and it might be very
// different from what was last in the commit panel. So the best we can do
// here is to always clear the remembered commit message.
self.commitsHelper.OnCommitSuccess()

@ChrisMcD1 ChrisMcD1 added the bug Something isn't working label May 11, 2025
@ChrisMcD1
Copy link
Contributor Author

I have just discovered that I can press <c-o> and e while in the commit panel to hop to my editor, and that version runs the above code that clears the preserved commit message. I don't know if I feel like changing my flow to use that set of keybindings, so I'm going to keep investigating the underlying fix.

But I never get this fixed, that is a valid workaround.

@ChrisMcD1 ChrisMcD1 linked a pull request May 11, 2025 that will close this issue
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant