Linux command
git-mv 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Rename a file
git mv [old-name.txt] [new-name.txt]
Move file to directory
git mv [file.txt] [directory/]
Force overwrite
git mv -f [source] [destination]
Move multiple files to a directory
git mv [file1.txt] [file2.txt] [directory/]
Dry run
git mv -n [source] [destination]
说明
git mv moves or renames files and directories while updating the Git index. It is equivalent to moving the file with `mv`, deleting the old path with `git rm`, and adding the new path with `git add`. Using this command ensures the rename is properly staged for the next commit. While Git can detect renames automatically through content analysis, using `git mv` makes the intent explicit and updates the index in one step.
参数
- -f, --force
- Force move/rename even if the destination exists.
- -k
- Skip move or rename actions that would lead to an error condition.
- -n, --dry-run
- Show what would happen.
- -v, --verbose
- Report moved files.
- --help
- Display help information.
FAQ
What is the git-mv command used for?
git mv moves or renames files and directories while updating the Git index. It is equivalent to moving the file with `mv`, deleting the old path with `git rm`, and adding the new path with `git add`. Using this command ensures the rename is properly staged for the next commit. While Git can detect renames automatically through content analysis, using `git mv` makes the intent explicit and updates the index in one step.
How do I run a basic git-mv example?
Run `git mv [old-name.txt] [new-name.txt]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -f, --force do in git-mv?
Force move/rename even if the destination exists.