1.6 KiB
1.6 KiB
Removing Files from Git History
This document outlines a secure, resource-efficient method to completely remove a file (and its traces) from a Git repository's history using git-filter-repo. This is useful for privacy-sensitive operations, such as removing accidentally committed secrets or sensitive data.
Prerequisites
- Git installed.
git-filter-repoinstalled (install viasudo apt install git-filter-repoon Debian-based systems if needed).- Admin access to the repository and remote (e.g., Gitea).
Steps
-
Verify the File in History:
cd /path/to/repo git log -- <file-path>This lists commits involving the file.
-
Remove the File from History:
git filter-repo --path <file-path> --invert-paths--invert-pathsexcludes the specified path from all commits.- This rewrites history and removes remotes as a safety measure.
-
Re-add Remote (if removed):
git remote add origin <remote-url> -
Force Push Changes:
git push origin --force --all- Use
--forceto overwrite remote history. Caution: This can break shared repos.
- Use
-
Verify Removal:
git log -- <file-path>No output means the file is gone.
Security Notes
- Always back up your repo before rewriting history.
- Use secure remotes (e.g., SSH).
- Avoid if the repo is public or has multiple collaborators without coordination.
- Follow least privilege: Run without sudo unless necessary.
This method is lightweight and respects resource constraints (low RAM/CPU usage).
Last updated: [Current Date]