Skip to content

Save failed commit messages somewhere? #9

Open

Description

@danbernier

When I write a commit message in my editor, and save and close it, if the message fails commitlint, I have to recreate everything I wrote (re-gather reference URLs, re-copy any supporting evidence for the reasoning in the commit, etc), from scratch.

It would be great if commitlint could keep a record of the last failed commit, so that a fresh git commit opens it up automatically, and you can make the (usually minor) necessary changes to pass commitlint.

Activity

  1. gumbo2k commented on Jul 15, 2024

    @gumbo2k
    Contributor

    I like that idea... I just had the same annoying experience. I wrote a lengthy commit message, commitlint said NO, and my long commit message was gone.

    Unfortunately I think it is not commitlint, but git itself, that removes the temporary file with the commit message.

    I guess it might be possible to create a copy of the file by simply adding a .bak to the filename if commitlint is called with a filename (and not reading the commit message from stdin.).
    If commitlint exits with an OK, it removes the .bak otherwise it prints the path to the file, so that you can recover the contents for the next attempt.

  2. danbernier commented on Jul 16, 2024

    @danbernier
    Author

    I wrote a lengthy commit message, commitlint said NO, and my long commit message was gone.

    It's SO frustrating!

    Your .bak file approach sounds workable. Even if (in the case of a "bad" commit message) you have to manually open the file and copy in its contents, and manually delete the file, it's far preferable to the toilet-flush that you experience this way.

  3. gumbo2k commented on Jul 16, 2024

    @gumbo2k
    Contributor

    Another idea might be a little more intrusive, but more helpful ... 🤔
    If we decide to fiddle about with git-config, we might save the "bad" message in a file and put its location in config.template ... Thus making git commit automatically open that file on the next commit and put it in the editor 😁

  4. gumbo2k commented on Feb 22, 2026

    @gumbo2k
    Contributor

    Another idea might be a little more intrusive, but more helpful ... 🤔 If we decide to fiddle about with git-config, we might save the "bad" message in a file and put its location in config.template ... Thus making git commit automatically open that file on the next commit and put it in the editor 😁

    I am still thinking about this solution.
    Changing the git config (even if it is only the config if the repository rhat you are currently working on) has the potential to mess up your work flow.
    There might be an alternative using prepare-commit-msg hook instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions