← 返回 Skills 市场
hhjin

Permanently Clear Files from Git History

作者 hhjin · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ✓ 安全检测通过
105
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install git-clear-committed-file-history
功能描述
Guide users to permanently remove files from Git repository history. Use this skill when users mention any of the following scenarios: - "git filter-repo", "...
使用说明 (SKILL.md)

Permanently Remove Files from Git History

When you delete a file in Git, it still remains in the Git repository history. This skill guides users to use the git filter-repo tool to permanently delete specified files from the complete history of a Git repository.

Applicable Scenarios

  • Accidentally committed sensitive information (passwords, API keys, private keys, tokens)
  • Accidentally committed large files, causing repository bloat
  • Need to clean up specific files from history
  • Need to remove a file from all branches and tags

Core Workflow

1. Important! First Step: Ask the User

Ask the user to confirm:

  • The repository path
  • Whether it's the current working directory
  • Whether they need to backup the repository (strongly recommended)

Must wait for user confirmation before proceeding with subsequent steps.

2. Backup Repository (Strongly Recommended)

Before performing any operations, backup the repository first:

# Method 1: Copy the entire repository directory
cp -r your-repo your-repo-backup

# Method 2: Create a bare repository backup
git clone --bare your-repo your-repo-backup.git

3. Install git filter-repo

Choose installation method based on your operating system:

macOS:

brew install git-filter-repo

Ubuntu / Debian:

pip install git-filter-repo

Windows:

pip install git-filter-repo

4. Verify Current Repository Status

After entering the repository directory, check:

git status
git remote -v

If there's no remote repository, add one first:

git remote add origin [email protected]:username/repository.git

5. Use git filter-repo to Delete Files

Assuming the file to delete is secrets.txt:

git filter-repo --path secrets.txt --invert-paths

What this step does:

  • Removes the file from all commits
  • Removes the file from all branches
  • Removes the file from all tags

Delete multiple files:

git filter-repo --path file1.txt --path file2.txt --path secrets/ --invert-paths

Delete entire directory:

git filter-repo --path directory-name/ --invert-paths

6. Verify File Has Been Deleted

Check if the file still exists in history:

git log --all -- filename

If there's no output, the file has been completely removed.

6. Force Push to Remote Repository

Because the history has been rewritten, a force push is required:

# Push all branches
git push origin --force --all

# Push all tags
git push origin --force --tags

Additional Steps After Removing Sensitive Information

If you deleted sensitive information (keys, tokens, passwords, private keys), in addition to deleting history, you should also:

Immediately Revoke Old Keys

  • Immediately revoke/delete old keys on the corresponding service platform (GitHub, AWS, Azure, etc.)
  • Generate new keys

Check Other Locations

  • Check if anyone else has forked the repository
  • Check CI/CD caches
  • Check if local clones still retain old content

Important Reminder: Just because history is deleted doesn't mean others haven't copied it before. Once sensitive information is committed to a public repository, it should be considered leaked.

Notify Collaborators

Because the commit history has changed, other people's local repositories will be inconsistent with the remote. You need to notify them:

  1. Re-clone the repository (recommended)

  2. Or execute the following command to sync:

    git fetch origin
    git reset --hard origin/main  # Will lose unpushed local changes, use with caution
    
  3. Warning: Do not continue development based on the old history, otherwise the deleted files will be reintroduced when pushing again

Common Issues

Q: Getting "fatal: not a git repository"?

Make sure you're executing commands in the Git repository root directory.

Q: Getting "git filter-repo: command not found"?

Install git-filter-repo first, refer to the installation steps above.

Q: Repository size hasn't decreased after deletion?

Run garbage collection:

git gc --aggressive --prune=now

Q: Only want to modify the most recent commit?

If the file is only in the most recent commit, you don't need filter-repo, use:

git rm --cached filename
git commit --amend

One-Liner Version

The most core commands:

# Delete file
git filter-repo --path filename --invert-paths

# If no remote, add first
git remote add origin \x3Crepo-url>

# Force push
git push origin --force --all
git push origin --force --tags
安全使用建议
This is a coherent, instruction-only guide for rewriting Git history. Before running any commands: (1) make a full backup and test on the backup, (2) coordinate with collaborators because history rewrite and force-push will disrupt others, (3) be prepared to revoke and rotate any exposed secrets after removal, (4) prefer installing git-filter-repo from trusted package sources and consider using a virtualenv or system package manager rather than system-wide pip where possible, (5) double-check branch names (main vs master) and remote names before running git reset --hard or force-push, and (6) verify removal locally (git log --all) and check forks/CI caches — history rewriting cannot guarantee removal from every clone or third-party cache.
功能分析
Type: OpenClaw Skill Name: git-clear-committed-file-history Version: 1.0.0 The skill bundle provides a legitimate and well-documented guide for using the 'git-filter-repo' tool to remove sensitive files or large assets from Git history. It includes necessary safety precautions, such as mandatory user confirmation and backup recommendations, and follows industry best practices for handling leaked credentials (SKILL.md).
能力评估
Purpose & Capability
The name/description match the SKILL.md instructions: all steps are about removing files from Git history using git-filter-repo, backing up, and force-pushing rewritten history. There are no unrelated environment variables, binaries, or external services requested.
Instruction Scope
The instructions stay on task (backup repository, install git-filter-repo, run filter-repo, verify, force-push, revoke keys, notify collaborators). They explicitly require user confirmation before destructive steps. They do include destructive operations (history rewrite and force-push) which are expected for the stated purpose and are appropriately warned.
Install Mechanism
Instruction-only skill (no install spec). It suggests installing git-filter-repo via brew or pip; those are reasonable but pip installs can affect the user's Python environment—user should prefer a system package manager or virtualenv and fetch the tool from trusted sources.
Credentials
The skill requests no credentials or environment variables. It does assume the user has Git remote access (SSH keys or auth tokens) to perform force-pushes, which is normal and proportional to the task.
Persistence & Privilege
Skill is instruction-only, not always-enabled, and does not request persistent system privileges or modify other skills or global agent settings.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install git-clear-committed-file-history
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /git-clear-committed-file-history 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
- Initial release of the git-filter-repo-remove-file skill. - Provides a step-by-step guide to permanently remove files from all Git repository history using git filter-repo. - Includes recommendations for backing up repositories and revoking compromised secrets. - Offers troubleshooting tips for common issues following a history rewrite. - Instructions address scenarios like removing sensitive data, large files, and ensuring all collaborators are informed of history changes.
元数据
Slug git-clear-committed-file-history
版本 1.0.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 1
常见问题

Permanently Clear Files from Git History 是什么?

Guide users to permanently remove files from Git repository history. Use this skill when users mention any of the following scenarios: - "git filter-repo", "... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 105 次。

如何安装 Permanently Clear Files from Git History?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install git-clear-committed-file-history」即可一键安装,无需额外配置。

Permanently Clear Files from Git History 是免费的吗?

是的,Permanently Clear Files from Git History 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

Permanently Clear Files from Git History 支持哪些平台?

Permanently Clear Files from Git History 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Permanently Clear Files from Git History?

由 hhjin(@hhjin)开发并维护,当前版本 v1.0.0。

💬 留言讨论