VS Code 中是否有任何方法可以更改文件名,以便将文件历史记录保留在 git 中,并且它不认为跟踪的文件已被删除?
我希望命令的 GUI 实现:
git mv oldName.abc newName.xyz
谢谢
VS Code 中是否有任何方法可以更改文件名,以便将文件历史记录保留在 git 中,并且它不认为跟踪的文件已被删除?
我希望命令的 GUI 实现:
git mv oldName.abc newName.xyz
谢谢
没有必要。只需重命名文件。无论是否git mv
使用,Git 都会检测重命名。
试试看:以正常方式重命名,以旧名称和新名称暂存文件(或只是 do git add .
)然后git status
在控制台中运行,它应该显示为重命名而不是创建和删除,所以历史总是保存。
Git 不存储文件重命名的信息。它仅在执行 diff 时(在git diff
/ status
/ log
/ 等)中检测到它。
有一个选项-M
可以控制此重命名检测的级别。
-M[<n>], --find-renames[=<n>]
Detect renames. If n is specified, it is a threshold on the similarity index (i.e. amount of addition/deletions compared to the file’s size).
For example, -M90% means Git should consider a delete/add pair to be a rename if more than 90% of the file hasn’t changed. Without a % sign,
the number is to be read as a fraction, with a decimal point before it. I.e., -M5 becomes 0.5, and is thus the same as -M50%. Similarly, -M05
is the same as -M5%. To limit detection to exact renames, use -M100%. The default similarity index is 50%.
试试看:
git status -M10%
对于 VS Code,你可以使用GitLens扩展,它提供了一个选项来控制这个阈值,这个设置被称为similarityThreshold
.
gitlens.advanced.similarityThreshold Specifies the amount (percent) of similarity a deleted and added file pair must have to be considered a rename
尝试将其设置为10
并通过 GitLens 检查历史记录,它应该更好地检测文件重命名。