我有两个文件index.html
和template.html
.我最感动的index.html
到template.html
现在的git认为我做了一个重命名当我添加这两个文件.在特定情况下是否可以防止这种情况?
Tod*_*obs 55
Git跟踪内容,而不是文件名.因此,如果两个文件具有基本相似的内容,git会认为您复制或重命名了该文件.如果您阅读git-log(1),您将学到:
相似性指数是未更改行的百分比,相异性指数是更改行的百分比.它是一个向下舍入的整数,后跟一个百分号.因此,100%的相似性索引值保留用于两个相等的文件,而100%的相异性意味着旧文件中的任何行都不会成为新文件.
因此,假设您的相似性指数为100%,git会认为这是一个副本.你最好的选择是添加一个合理的日志消息或注释(有关更多信息,请参阅git-notes(1)),以解释如果你认为git没有做正确的事情会发生什么.
您也可以尝试调整git用于考虑复制或重命名的值.git-log手册(1)说:
-M[<n>], --find-renames[=<n>]
If generating diffs, detect and report renames for each commit. For
following files across renames while traversing history, see --follow. 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.
-C[<n>], --find-copies[=<n>]
Detect copies as well as renames. See also --find-copies-harder.
If n is specified, it has the same meaning as for -M<n>.
Run Code Online (Sandbox Code Playgroud)
同样,这不会帮助你,如果这些文件大多是相似的,但你当然可以使用这些值来调整如何,他们需要类似是为了被认为是副本或重命名.你的旅费可能会改变.
Bas*_*usa 20
如果你在提交之前的那一刻和"你感觉不好git发疯了",那么只需撤消添加模糊文件git认为你重命名,执行提交,然后再次添加模糊文件并提交:
git reset ambiguous_file_git_thought_you_renamed
git commit
git add ambiguous_file_git_thought_you_renamed
git commit
Run Code Online (Sandbox Code Playgroud)
这对我有用.
仔细检查没有重命名:
git diff --name-status -C HEAD^^ HEAD
M ambiguous_file_git_thought_you_renamed
M original_file
Run Code Online (Sandbox Code Playgroud)
开头的"M"表示已修改,"R"表示已重命名.注意此处没有重命名.
mat*_*mat 13
有一个"接受"的答案,但它没有提供任何关于如何回答问题的提示.
从git-log(1)和git-diff(1)得到的正确答案是:
--no-renames
Turn off rename detection, even when the configuration
file gives the default to do so.
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
19519 次 |
最近记录: |