首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Git归咎于-C -C似乎行不通

Git归咎于-C -C似乎行不通
EN

Stack Overflow用户
提问于 2018-05-16 19:11:09
回答 1查看 308关注 0票数 2

command中,它说(强调我的):

C< num > 除了-M之外,检测从在同一提交中修改的其他文件中移动或复制的行。当您重新组织程序并在文件之间移动代码时,这是非常有用的。当给出该选项两次时,该命令还将查找创建该文件的提交中的其他文件的副本。当该选项被赋予三次时,该命令还将在任何提交中查找其他文件的副本。..。

首先,“创建文件的提交中的其他文件”意味着什么?它是否查找在添加文件的同一提交中修改的文件?还是查找仅存在于添加文件的提交树中的所有文件?

我尝试了一个例子,在同一个提交中创建一个非空文件(名为source)和一个空文件(名称为dest)。在接下来的提交中,我做了一些无关的事情。在第三次也是最后一次提交中,我将几行代码从source复制到dest。结果如下(内容相当大,不能混淆git的算法,我对此表示歉意):

代码语言:javascript
复制
$ git init
$ cat source
--incremental         Show blame entries as we find them, incrementally
-b                    Show blank SHA-1 for boundary commits (Default: off)
--root                Do not treat root commits as boundaries (Default: off)
--show-stats          Show work cost statistics
--score-debug         Show output score for blame entries
-f, --show-name       Show original filename (Default: auto)
-n, --show-number     Show original linenumber (Default: off)
-p, --porcelain       Show in a format designed for machine consumption
--line-porcelain      Show porcelain format with per-line commit information
-c                    Use the same output mode as git-annotate (Default: off)
-t                    Show raw timestamp (Default: off)
-l                    Show long commit SHA1 (Default: off)
-s                    Suppress author name and timestamp (Default: off)
-e, --show-email      Show author email instead of name (Default: off)
-w                    Ignore whitespace differences
--minimal             Spend extra cycles to find better match
-S <file>             Use revisions from <file> instead of calling git-rev-list
--contents <file>     Use <file>'s contents as the final image
-C[<score>]           Find line copies within and across files
-M[<score>]           Find line movements within and across files
-L <n,m>              Process only line range n,m, counting from 1
--abbrev[=<n>]        use <n> digits to display SHA-1s

$ cat dest
first initial line in dest
second initial line in dest

$ git add source dest
$ git commit -m "Add source and dest files"
$ touch new-file
$ git add new-file
$ git commit -m "Add irrelevant file"
$ (copy some lines from source to dest)
$ cat dest
first initial line in dest
--show-stats          Show work cost statistics
--score-debug         Show output score for blame entries
-f, --show-name       Show original filename (Default: auto)
-n, --show-number     Show original linenumber (Default: off)
-p, --porcelain       Show in a format designed for machine consumption
--line-porcelain      Show porcelain format with per-line commit information
-c                    Use the same output mode as git-annotate (Default: off)
-t                    Show raw timestamp (Default: off)
-l                    Show long commit SHA1 (Default: off)
-s                    Suppress author name and timestamp (Default: off)
-e, --show-email      Show author email instead of name (Default: off)
-w                    Ignore whitespace differences
--minimal             Spend extra cycles to find better match
-S <file>             Use revisions from <file> instead of calling git-rev-list
--contents <file>     Use <file>'s contents as the final image
second initial line in dest

$ git add dest
$ git commit -m "Copy lines from source to dest"
$ git log --pretty=oneline
6b0f18daaf83ec83d3f53b4a43f4188de3ce87e6 copy lines from source to dest
f1d66ad3dacb8e589747ed02b42d9135081b3704 Add irrelevant file
2b8275dc73ffd88d7adb6f90a2050ef14088019a Add source and dest files

$ git blame dest
^2b8275d -  1) first initial line in dest
6b0f18da -  2)     --show-stats          Show work cost statistics
6b0f18da -  3)     --score-debug         Show output score for blame entries
6b0f18da -  4)     -f, --show-name       Show original filename (Default: auto)
6b0f18da -  5)     -n, --show-number     Show original linenumber (Default: off)
6b0f18da -  6)     -p, --porcelain       Show in a format designed for machine consumption
6b0f18da -  7)     --line-porcelain      Show porcelain format with per-line commit information
6b0f18da -  8)     -c                    Use the same output mode as git-annotate (Default: off)
6b0f18da -  9)     -t                    Show raw timestamp (Default: off)
6b0f18da - 10)     -l                    Show long commit SHA1 (Default: off)
6b0f18da - 11)     -s                    Suppress author name and timestamp (Default: off)
6b0f18da - 12)     -e, --show-email      Show author email instead of name (Default: off)
6b0f18da - 13)     -w                    Ignore whitespace differences
6b0f18da - 14)     --minimal             Spend extra cycles to find better match
6b0f18da - 15)     -S <file>             Use revisions from <file> instead of calling git-rev-list
6b0f18da - 16)     --contents <file>     Use <file>'s contents as the final image
^2b8275d - 17) second initial line in dest
$ git blame -C dest
^2b8275d -  1) first initial line in dest
6b0f18da -  2)     --show-stats          Show work cost statistics
6b0f18da -  3)     --score-debug         Show output score for blame entries
6b0f18da -  4)     -f, --show-name       Show original filename (Default: auto)
6b0f18da -  5)     -n, --show-number     Show original linenumber (Default: off)
6b0f18da -  6)     -p, --porcelain       Show in a format designed for machine consumption
6b0f18da -  7)     --line-porcelain      Show porcelain format with per-line commit information
6b0f18da -  8)     -c                    Use the same output mode as git-annotate (Default: off)
6b0f18da -  9)     -t                    Show raw timestamp (Default: off)
6b0f18da - 10)     -l                    Show long commit SHA1 (Default: off)
6b0f18da - 11)     -s                    Suppress author name and timestamp (Default: off)
6b0f18da - 12)     -e, --show-email      Show author email instead of name (Default: off)
6b0f18da - 13)     -w                    Ignore whitespace differences
6b0f18da - 14)     --minimal             Spend extra cycles to find better match
6b0f18da - 15)     -S <file>             Use revisions from <file> instead of calling git-rev-list
6b0f18da - 16)     --contents <file>     Use <file>'s contents as the final image
^2b8275d - 17) second initial line in dest
$ git blame -C -C dest
^2b8275d -  1) first initial line in dest
6b0f18da -  2)     --show-stats          Show work cost statistics
6b0f18da -  3)     --score-debug         Show output score for blame entries
6b0f18da -  4)     -f, --show-name       Show original filename (Default: auto)
6b0f18da -  5)     -n, --show-number     Show original linenumber (Default: off)
6b0f18da -  6)     -p, --porcelain       Show in a format designed for machine consumption
6b0f18da -  7)     --line-porcelain      Show porcelain format with per-line commit information
6b0f18da -  8)     -c                    Use the same output mode as git-annotate (Default: off)
6b0f18da -  9)     -t                    Show raw timestamp (Default: off)
6b0f18da - 10)     -l                    Show long commit SHA1 (Default: off)
6b0f18da - 11)     -s                    Suppress author name and timestamp (Default: off)
6b0f18da - 12)     -e, --show-email      Show author email instead of name (Default: off)
6b0f18da - 13)     -w                    Ignore whitespace differences
6b0f18da - 14)     --minimal             Spend extra cycles to find better match
6b0f18da - 15)     -S <file>             Use revisions from <file> instead of calling git-rev-list
6b0f18da - 16)     --contents <file>     Use <file>'s contents as the final image
^2b8275d - 17) second initial line in dest
$ git blame -C -C -C dest
^2b8275d dest   -  1) first initial line in dest
^2b8275d source -  2)     --show-stats          Show work cost statistics
^2b8275d source -  3)     --score-debug         Show output score for blame entries
^2b8275d source -  4)     -f, --show-name       Show original filename (Default: auto)
^2b8275d source -  5)     -n, --show-number     Show original linenumber (Default: off)
^2b8275d source -  6)     -p, --porcelain       Show in a format designed for machine consumption
^2b8275d source -  7)     --line-porcelain      Show porcelain format with per-line commit information
^2b8275d source -  8)     -c                    Use the same output mode as git-annotate (Default: off)
^2b8275d source -  9)     -t                    Show raw timestamp (Default: off)
^2b8275d source - 10)     -l                    Show long commit SHA1 (Default: off)
^2b8275d source - 11)     -s                    Suppress author name and timestamp (Default: off)
^2b8275d source - 12)     -e, --show-email      Show author email instead of name (Default: off)
^2b8275d source - 13)     -w                    Ignore whitespace differences
^2b8275d source - 14)     --minimal             Spend extra cycles to find better match
^2b8275d source - 15)     -S <file>             Use revisions from <file> instead of calling git-rev-list
^2b8275d source - 16)     --contents <file>     Use <file>'s contents as the final image
^2b8275d dest   - 17) second initial line in dest

可以看到,git blame -C -C dest没有意识到dest中的新行来自于source,该文件与dest在同一个提交中使用这些行创建。然而,git blame -C -C -C dest提供了预期的输出。

我做错了什么吗?

谢谢。

编辑:

我相信

..。当给出该选项两次时,该命令还将查找创建该文件的提交中的其他文件的副本。..。

这意味着git将查找实际创建文件的提交中只发生的行副本(来自其他文件),而不是从其他文件(创建文件的提交中存在的文件)中查找行副本。这种误解与我的第一个问题有关。

EN

回答 1

Stack Overflow用户

发布于 2020-07-10 14:07:42

git来说,这似乎是一种假设,即您无法从不存在的东西中复制。如果您在以前的提交中首先创建源文件,那么-C -C应该可以工作。如果您在当前提交中也对其进行了修改,则只有-C也能工作。

如果git不是这样工作的,那么他们就必须关注在提交中应用更改的顺序,这可能会使代码变得更加毛茸茸(在您的示例中:从哪个文件复制到哪个文件?git怎么知道,因为它们都是在同一个提交中创建的?)。

根据你自己的实验结果,回答你的第一个问题:

当给出该选项两次时,命令还将查找创建该文件的提交中的其他文件的副本。

表示在创建文件的提交之前存在于树中的所有文件。

-C -C -C检查所有提交,因此也检查创建文件的提交。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50378366

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档