Linux command
git-rm 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Remove file from tracking
git rm [file.txt]
Remove directory
git rm -r [directory/]
Remove from index only
git rm --cached [file.txt]
Force remove
git rm -f [file.txt]
Dry run
git rm -n [file.txt]
说明
git rm removes files from the working tree and the index, staging the removal for the next commit. The `--cached` option removes files from tracking while keeping them on disk, which is useful for files that should have been in `.gitignore`. Without `--cached`, the file is deleted from both the working tree and the index.
参数
- --cached
- Remove from index only, keep file.
- -r
- Recursive removal.
- -f, --force
- Force removal.
- -n, --dry-run
- Show what would be removed.
- --ignore-unmatch
- Exit successfully even if no match.
- --help
- Display help information.
FAQ
What is the git-rm command used for?
git rm removes files from the working tree and the index, staging the removal for the next commit. The `--cached` option removes files from tracking while keeping them on disk, which is useful for files that should have been in `.gitignore`. Without `--cached`, the file is deleted from both the working tree and the index.
How do I run a basic git-rm example?
Run `git rm [file.txt]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does --cached do in git-rm?
Remove from index only, keep file.