Rya*_*thm 15 git visual-studio-code
VS Code 中是否有任何方法可以更改文件名,以便将文件历史记录保留在 git 中,并且不会认为跟踪的文件已被删除?
我希望命令的 GUI 实现:
git mv oldName.abc newName.xyz
Run Code Online (Sandbox Code Playgroud)
谢谢
Che*_*yDT 11
没有必要。只需重命名文件。无论是否git mv使用,Git 都会检测重命名。
试试看:以正常方式重命名,以旧名称和新名称暂存文件(或直接执行git add .),然后git status在控制台中运行,它应该显示为重命名而不是创建和删除,所以历史总是保存。
Jer*_*ers 10
由于 git 有时无法检测重命名操作,我已在 Visual Studio Code 中安装了此扩展,到目前为止,该扩展似乎可以很好地重命名文件并在git mv下面执行以下操作:
https://marketplace.visualstudio.com/items?itemName=ambooth.git-rename
README.md中最酷的一点是,在重命名期间可以指定新的目录位置:
用法
右键单击文件资源管理器中的文件并选择“重命名 (git-mv)”。使用出现的输入文本字段,输入新名称并按 Enter 键。注意:还可以通过调整路径来更改目录位置。
Git 不存储文件被重命名的信息。它仅在进行比较时才检测到它(在git diff///status等中log)。(来源)
有一个选项-M可以控制重命名检测的级别。
-M[<n>], --find-renames[=<n>]\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\xe2\x80\x99s size).\n For example, -M90% means Git should consider a delete/add pair to be a rename if more than 90% of the file hasn\xe2\x80\x99t changed. Without a % sign,\n 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\n is the same as -M5%. To limit detection to exact renames, use -M100%. The default similarity index is 50%.\nRun Code Online (Sandbox Code Playgroud)\n尝试一下:
\ngit status -M10%\nRun Code Online (Sandbox Code Playgroud)\n对于 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\nRun Code Online (Sandbox Code Playgroud)\n尝试将其设置为10并通过 GitLens 检查历史记录,它应该可以更好地检测文件重命名。
| 归档时间: |
|
| 查看次数: |
2949 次 |
| 最近记录: |