mirror of
https://github.com/f/git-rewrite-commits.git
synced 2026-04-27 06:35:49 +03:00
[GH-ISSUE #2] Error on execution #2
Labels
No labels
bug
enhancement
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/git-rewrite-commits#2
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @sebastienbarre on GitHub (Nov 10, 2025).
Original GitHub issue: https://github.com/f/git-rewrite-commits/issues/2
Thank you for making this tool available.
On macOS 26.1 (MacBook Pro M4), I'm getting errors after running:
I abbreviated the path names below.
Note that I have no
git/filter-msg.js, I assume you are trying to create that file?@f commented on GitHub (Nov 10, 2025):
It should be creating that file.
@sebastienbarre commented on GitHub (Nov 10, 2025):
Yes I assume it is, but seems to be failing at it.
The repo is private, but I can share more info if needed.
I'm running node v24.11.0
@sebastienbarre commented on GitHub (Nov 14, 2025):
Anybody who runs this script in a repo where
package.jsonhas"type": "module"will encounter the same problem apparently. Unfortunately I can't change it temporarily to "commonjs" because it then errors with "Cannot rewrite branches: You have unstaged changes.", and if I try to commit it everything in my lint-staged blows up (and rejects the commit).@willtheorangeguy commented on GitHub (Nov 14, 2025):
Should be fixed in #15. @sebastienbarre do you think you can test the changes on Mac?
@f commented on GitHub (Nov 15, 2025):
Should be fixed with the new version.
@sebastienbarre commented on GitHub (Nov 15, 2025):
It is executing now, but there is something FUNDAMENTALLY BROKEN right now with this script, which will very much mess with people's repository. Hopefully this is only with respect to the "--max-commits" option.
I can't afford to reproduce it more, but I ran it this way, limiting myself to 40 commits to be safe:
I have about 230+ commits in my repo; let’s say 240 for the sake of this explanation. I’ll call commit #1 the very first (oldest) commit, and commit #240 the most recent. The script inspected my repo starting with the most recent commit (#240) and counting down 40 of them (back to #201).
The last (most recent) 35 commits were already using conventional commit messages (i.e., commits #240 back through #206). The script correctly identified them as such and ignored them. It then analyzed the 5 commits before that and suggested good replacements (i.e. commits #205 to #201, going back in time).
So at that point, I could see 40 commit messages on screen with nice, conventional messages—5 of them coming from this script. I confirmed the choice.
This is where it went very wrong!
Instead of modifying commits #240 to #201, it left them untouched and used those new messages to overwrite commits #40 down to #1 instead! In other words, instead of rewriting the messages at the top of the history, where they were found, it rewrote them at the bottom.
As a result, I’ve now “lost” the original messages for the first (oldest) 40 commits in my repo.
For example, this commit is #203, from Nov 6, 2025 (the 38th this script inspected):
The script suggested "refactor(AGENTS.md): Refactor content structure for clarity and consistency".
Fair enough as a message, except that it was left untouched and it’s now the message for commit #3 instead, which originally dated from Oct 3, 2025 and has nothing to do with this file. Similarly, the message intended for commit #202 is now slapped on commit #2, and the message for commit #201 is now on commit #1 instead; my oldest commit. I’ve lost the original “First commit” message.
Thankfully this is a recent, private repo, but it is borked now.
The order and contents of the commits seem fine, but my most recent 40 commit messages have now overwritten my first (oldest) 40 commit messages.