Git
简体中文 ▾ Topics ▾ Latest version ▾ git-mv last updated in 2.44.0

名称

git-mv - 移动或重命名一个文件、一个目录或一个符号链接

概述

git mv [<options>] <source>…​ <destination>

描述

移动或重命名一个文件、目录或符号链接。

git mv [-v] [-f] [-n] [-k] <source> <destination>
git mv [-v] [-f] [-n] [-k] <source> ... <destination-directory>

In the first form, it renames <source>, which must exist and be either a file, symlink or directory, to <destination>. In the second form, the last argument has to be an existing directory; the given sources will be moved into this directory.

在移动成功完成后,索引就会被更新,但更改仍需要进行提交才能生效。

选项

-f
--force

即使 <目标文件> 存在,也强制重命名或移动文件。

-k

跳过可能导致错误条件的移动或重命名操作。当源文件既不存在也不受Git控制,或者在没有提供 -f 选项的情况下覆盖现有文件时,该指令就会就会发生错误。

-n
--dry-run

什么都不做,仅显示将会发生的操作

-v
--verbose

报告文件在移动时的名称的变化。

子模块

Moving a submodule using a gitfile (which means they were cloned with a Git version 1.7.8 or newer) will update the gitfile and core.worktree setting to make the submodule work in the new location. It also will attempt to update the submodule.<name>.path setting in the gitmodules[5] file and stage that file (unless -n is used).

漏洞

每当父工程更新导致子模块移动时(例如,在移动之前和之后的提交之间切换时),旧位置将保留一个陈旧的子模块检出,并在新位置出现一个空目录。要在新位置重新填充子模块,用户必须运行 "git submodule update"。只有在旧目录使用 gitfile 时,删除旧目录才是安全的,否则子模块的历史记录也将被删除。当实现递归子模块更新时,这两个步骤将变得不再需要。

GIT

属于 git[1] 文档

scroll-to-top