commit-delete
v1.0.1
Published
Reset the Git history of a repository while keeping the current files intact.
Maintainers
Readme
Commit-delete
Reset the Git history of a repository while keeping the current files intact.
Commit-delete is a lightweight, dependency-free Node.js CLI tool that replaces
the entire Git history of the current repository with a single initial release
commit and force-pushes the result to origin/master.
⚠️ WARNING: This tool is destructive. It permanently deletes the existing Git history of the repository and force-pushes the new history. Other users working on the repository may need to re-clone or reset their local copy.
Usage
cd my-project
commit-deleteThe CLI:
- Verifies Git is installed.
- Verifies the current directory is a Git repository.
- Shows the repository information (path, branch, remote, remote URL, commit count).
- In an interactive terminal, lets you pick the target branch, remote and commit message.
- Shows a clear warning and a configuration preview.
- Asks for confirmation — No is the default.
- On confirmation, executes:
git checkout --orphan latest_branch
git add -A
git commit -am "<message>"
git branch -D <old-branch>
git branch -M <target-branch>
git push -f <remote> <target-branch>Options
| Flag | Description |
|------|-------------|
| -b, --branch <name> | Target branch (default: current branch) |
| -r, --remote <name> | Remote to push to (default: origin) |
| -m, --message <text> | Commit message (default: initial release) |
| -y, --yes | Skip the confirmation prompt |
| -n, --dry-run | Show the commands without executing them |
| -h, --help | Show this help |
When stdin is not a terminal (for example in scripts or CI), the branch, remote
and commit message default to the current branch, origin and initial release,
and can be overridden with the flags above.
Installation
Globally via npm
npm install -g commit-deleteFrom source
npm install
npm link
commit-deleteDevelopment
npm testTests create temporary Git repositories (including a bare remote) and verify the full flow end-to-end.
How it works
Before the operation:
commit A
↓
commit B
↓
commit CAfter commit-delete:
initial releaseThe current files are preserved. Only the history is rewritten.
Requirements
- Node.js 18+
- Git
- A valid Git repository
- A remote to push to (default
origin) - Permission to force-push to the remote
Error handling
Every Git command is checked for failure. If a command fails, Commit-delete stops, shows the failed command and the Git error, and exits with a non-zero exit code.
If the local history was rewritten but the remote push fails (for example when
origin is missing or push permission is denied), the CLI clearly states that
the local repository is using the new history and that the push must be done
manually.
Safety
- The tool never initializes a Git repository automatically.
- It never deletes project files.
- It never asks for Git credentials — authentication is left to Git itself.
- The confirmation happens before any repository state is changed.
