Skip to content

Conversation

aidancz
Copy link
Contributor

@aidancz aidancz commented Jul 13, 2025

  • PR Description

When the commit message is empty, the --amend command will produce an error.
Solution: Add the --allow-empty-message option.

  • Please check if the PR fulfills these requirements
  • Cheatsheets are up-to-date (run go generate ./...)
  • Code has been formatted (see here)
  • Tests have been added/updated (see here for the integration test guide)
  • Text is internationalised (see here)
  • If a new UserConfig entry was added, make sure it can be hot-reloaded (see here)
  • Docs have been updated if necessary
  • You've read through your own file changes for silly mistakes etc

@stefanhaller
Copy link
Collaborator

This makes sense to me for AmendHeadCmdObj, ResetAuthor, and SetAuthor. If you have a commit whose message is already empty, it should be possible to add file changes to it or reset its author without getting an error. This can be seen as a bug fix.

I am a little less sure about RewordLastCommit and RewordLastCommitInEditor; this would now allow rewording a commit to make its message empty, which wasn't possible before. To me this would be more of a behavior change than a bug fix.

What's your use case? Why do you want to work with commits with empty messages at all? You didn't give a rationale for this in #4643 either.

@aidancz
Copy link
Contributor Author

aidancz commented Jul 13, 2025

I sometimes make commits with an empty message in the following situation:

When a stage of work is completed, but the overall task isn’t finished yet.

The reason is:

After committing, I no longer need to worry about losing changes. An empty commit message stands out clearly in the commit history, reminding me that this is just a partial milestone. Later, I can squash these into a single commit with a proper message.

Regarding the behavior change in LazyGit:

For #4643, the c enter key sequence is very easy to press, but it’s currently underutilized. Having it create a commit with an empty message seems like the most reasonable behavior in that UI context ,after all, Enter means “confirm.” If the user wants to cancel the commit, pressing Esc would be more appropriate.

As for this PR, I believe allowing an empty message during rewording is a reasonable change. Here’s why:
1. For RewordLastCommit, the same logic applies: allowing an empty message makes sense in this UI context
2. For RewordLastCommitInEditor, it’s possible that some users might delete all content in the editor to cancel the reword. However, I think that’s not a very healthy habit. If many users do operate this way, perhaps a confirmation dialog could be added?
3. Even if a user makes a mistake, they can easily understand what happened from the command history and just reword again.
4. Finally, if #4643 is updated, this change should be made here as well for consistency.

@stefanhaller
Copy link
Collaborator

An empty commit message stands out clearly in the commit history, reminding me that this is just a partial milestone.

I don't understand why it needs to be empty for this. A message such as - would also stand out clearly, and wouldn't have the tooling problems you are trying to solve here.

Having it create a commit with an empty message seems like the most reasonable behavior in that UI context

I disagree with this, as I said in #4643; this has the potential of accidentally creating commits with empty messages, which is something that most people probably don't want to do.

For rewording, it seems less like a problem to me, as you would have to actively delete all text before pressing enter, so this is not something that would happen accidentally. However:

For RewordLastCommitInEditor, it’s possible that some users might delete all content in the editor to cancel the reword.

Yes, this is actually what I do. It sometimes happens that I accidentally hit shift-r instead of r to rename (confusing this with the branches panel, where it's shift-r for renaming a branch), and then deleting all text and saving seems like the only way to cleanly abort the rename. How else would you do it? Most editors don't have a way to say "quit with an error code".

For this reason I'm strongly against allowing empty messages for RewordLastCommitInEditor, and then I would keep RewordLastCommit unchanged as well for consistency.

I'm fine with changing the remaining three commands, if you still find that valuable enough. If so, please fix the failing unit tests.

@aidancz aidancz force-pushed the amend-allow-empty-message branch 2 times, most recently from ccfb499 to 3de5e28 Compare July 14, 2025 03:31
@aidancz
Copy link
Contributor Author

aidancz commented Jul 14, 2025

I understand your point of view, this PR has been updated

@stefanhaller stefanhaller added the bug Something isn't working label Jul 14, 2025
@stefanhaller stefanhaller force-pushed the amend-allow-empty-message branch from 3de5e28 to 0451a16 Compare July 14, 2025 15:58
@stefanhaller stefanhaller changed the title Fix --amend when the commit message is empty Fix amending commits whose commit message is empty Jul 14, 2025
@stefanhaller stefanhaller enabled auto-merge July 14, 2025 15:59
@stefanhaller
Copy link
Collaborator

Thanks!

@stefanhaller stefanhaller merged commit 1210a64 into jesseduffield:master Jul 14, 2025
13 checks passed
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Aug 4, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [jesseduffield/lazygit](https://github.com/jesseduffield/lazygit) | minor | `v0.53.0` -> `v0.54.0` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>jesseduffield/lazygit (jesseduffield/lazygit)</summary>

### [`v0.54.0`](https://github.com/jesseduffield/lazygit/releases/tag/v0.54.0)

[Compare Source](jesseduffield/lazygit@v0.53.0...v0.54.0)

<!-- Release notes generated using configuration in .github/release.yml at v0.54.0 -->

Again we don't have any major new features this time (unless you count the support for alt-backspace for deleting words in the commit message editor, which is one of my favorite additions), but lots of smaller quality-of-life improvements and bug fixes. The most notable one is probably the fix for the stale index.lock problem, which was a very long-standing bug that seemed to affect some users much more than others for some reason.

#### What's Changed

##### Enhancements 🔥

- Add confirmation for hard reset by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4704
- Provide user config defaults for UI-changeable settings by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4717
- Improve mouse handling of suggestions panel by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4726
- Add new command "Checkout previous branch" by [@&#8203;kyu08](https://github.com/kyu08) in jesseduffield/lazygit#4728
- Add confirmation for nuking the working tree by [@&#8203;DawidPietrykowski](https://github.com/DawidPietrykowski) in jesseduffield/lazygit#4727
- Support Alt+Backspace for word deletion in text areas by [@&#8203;rtzll](https://github.com/rtzll) in jesseduffield/lazygit#4741
- Don't use hunk mode for added or deleted files even when useHunkModeInStagingView config is on by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4758
- Show \[0] keybinding in main view title by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4754
- Draw divergence from base branch right-aligned in branches view by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4785
- Enable hunk staging mode by default by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4780

##### Fixes 🔧

- Fix scrolling hunk into view when selecting next hunk by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4709
- Fix stale main view content when entering/exiting filtering view by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4719
- Detect double-clicks properly by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4725
- Fix commit searching during rebase or in divergence from upstream view by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4730
- Fix amending commits whose commit message is empty by [@&#8203;aidancz](https://github.com/aidancz) in jesseduffield/lazygit#4732
- Several small fixes to filtering mode (by path or author) by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4749
- Show diff for renamed file when filtering by path by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4750
- Allow rewording or dropping commits in filtering mode by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4756
- Fix index out of bounds panic when repository has massive tags by [@&#8203;chojs23](https://github.com/chojs23) in jesseduffield/lazygit#4776
- When pressing `a` to stage all files, don't include untracked files when showing only tracked files by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4779
- Fix commit hash colors when filtering by path or aythor by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4789
- Improve temp dir handling by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4784
- Terminate git processes more gracefully to avoid the stale index.lock problem by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4782

##### Maintenance ⚙️

- Raise sponsors MRs as a draft by [@&#8203;jesseduffield](https://github.com/jesseduffield) in jesseduffield/lazygit#4694
- Update the peter-evans/create-pull-request action to v7 by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4695
- Update release workflow by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4703
- Clean up the .gitignore file by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4706
- Remove unused code and texts by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4715
- Remove deprecated edit configs by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4716
- Bump minimum required git version to 2.32 by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4718
- Use a better way of pinning the version of golangci-lint by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4733
- Make the minimum required git version a placeholder in the error text by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4778
- refactor: use slices.Equal to simplify code by [@&#8203;jishudashu](https://github.com/jishudashu) in jesseduffield/lazygit#4764

##### Docs 📖

- Fix broken markdown in auto-generated keybindings documentation by [@&#8203;KEY60228](https://github.com/KEY60228) in jesseduffield/lazygit#4690
- Remove the homebrew tap from the readme by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4705

##### I18n 🌎

- Update translations from Crowdin by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4791

##### Performance Improvements 📊

- Fix performance regression on startup in repos with many tags by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4777

#### New Contributors

- [@&#8203;KEY60228](https://github.com/KEY60228) made their first contribution in jesseduffield/lazygit#4690
- [@&#8203;DawidPietrykowski](https://github.com/DawidPietrykowski) made their first contribution in jesseduffield/lazygit#4727
- [@&#8203;rtzll](https://github.com/rtzll) made their first contribution in jesseduffield/lazygit#4741
- [@&#8203;chojs23](https://github.com/chojs23) made their first contribution in jesseduffield/lazygit#4776
- [@&#8203;jishudashu](https://github.com/jishudashu) made their first contribution in jesseduffield/lazygit#4764

**Full Changelog**: jesseduffield/lazygit@v0.53.0...v0.54.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS40Ni43IiwidXBkYXRlZEluVmVyIjoiNDEuNDYuNyIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90Il19-->
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 this pull request may close these issues.

2 participants