Linux command
git-filter-branch 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Remove file from history
git filter-branch --tree-filter 'rm -f [file]' HEAD
Rewrite author
git filter-branch --env-filter 'GIT_AUTHOR_EMAIL="[new@email]"' HEAD
Subdirectory filter
git filter-branch --subdirectory-filter [dir] HEAD
Remove empty commits
git filter-branch --prune-empty HEAD
Force rewrite
git filter-branch -f --tree-filter '[command]' HEAD
说明
git filter-branch is a powerful but deprecated tool for rewriting Git history by applying filter commands to every commit in a branch. It walks through the entire commit history, allowing modifications to trees, commit messages, author information, or other metadata. The subdirectory-filter is particularly useful for extracting a subdirectory into a new repository with its history intact. Performance is notably poor on large repositories because it must check out every commit's tree. This limitation led to the development of git-filter-repo as the official replacement.
参数
- --tree-filter _cmd_
- Rewrite tree and contents.
- --env-filter _cmd_
- Modify environment.
- --msg-filter _cmd_
- Rewrite commit messages.
- --subdirectory-filter _dir_
- Extract subdirectory.
- --prune-empty
- Remove empty commits.
- -f, --force
- Force overwrite backup.
FAQ
What is the git-filter-branch command used for?
git filter-branch is a powerful but deprecated tool for rewriting Git history by applying filter commands to every commit in a branch. It walks through the entire commit history, allowing modifications to trees, commit messages, author information, or other metadata. The subdirectory-filter is particularly useful for extracting a subdirectory into a new repository with its history intact. Performance is notably poor on large repositories because it must check out every commit's tree. This limitation led to the development of git-filter-repo as the official replacement.
How do I run a basic git-filter-branch example?
Run `git filter-branch --tree-filter 'rm -f [file]' HEAD` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does --tree-filter _cmd_ do in git-filter-branch?
Rewrite tree and contents.