为什么`git blame -w`不忽略换行符?

影影

所以,给定一个换行符的变化 变更集

$ git blame -w -L70,71 file

$ git blame -w -M -L70,71 file

上面的这两个命令给了我完全相同的输出:

523cdb67 (Nick Mikhno 2017-05-26 18:00:13 +0300 70)                     <span id="contactPhoneNumberError"
523cdb67 (Nick Mikhno 2017-05-26 18:00:13 +0300 71)                     class="errorSpan"></span>

例如 git 责怪我更改行,但我需要忽略 git 注释中的换行符我想看到实际更改代码的前一个用户并忽略代码重新格式化

根据 $ git blame --help

-w
    Ignore whitespace when comparing the parent’s version and the child’s to find where the lines came from.


-M|<num>|
    Detect moved or copied lines within a file. When a commit moves or copies a block of lines (e.g. the original file has A and then B, and the commit changes it to B and then A), the traditional blame algorithm notices only half of the movement and typically blames the lines that were moved up (i.e. B) to the parent and assigns blame to the lines that were moved down (i.e. A) to the child commit. With this option, both groups of lines are blamed on the parent by running extra passes of inspection.

    <num> is optional but it is the lower bound on the number of alphanumeric characters that Git must detect as moving/copying within a file for it to associate those lines with the parent commit. The default value is 20.

请告诉我,我错在哪里?

贾斯汀霍华德

假设您有文件:

Hello world!

然后运行

> git blame hello.txt
^dd5c453 (User1 2017-05-26 13:50:54 -0700 1) Hello world!

现在 User2 出现并添加了额外的空间

> git blame hello.txt
fdd9abbe (User2 2017-05-26 13:51:50 -0700 1) Hello     world!

> git blame -w hello.txt
^dd5c453 (User1 2017-05-26 13:50:54 -0700 1) Hello     world!

您可以看到使用该-w标志会忽略 User2 添加的空格。问题是每一行都是为blame 命令单独评估的。这意味着即使我们使用-w,分割或加入行也总是会改变被指责的用户。

> git blame -w hello.txt
c0c338a5 (User3 2017-05-26 13:55:52 -0700 1) Hello
c0c338a5 (User3 2017-05-26 13:55:52 -0700 2) world!

-M国旗也是一样拆分一条线不被视为移动,因为 git 将合并的线视为与两条拆分线不同的数据。您可以将其视为删除合并的行并添加两个新行。

那么如果责备不起作用,你如何找到原作者我经常使用git log --follow -p hello.txt. 这将显示每个更改的提交hello.txt以及每个更改的完整差异。

commit c0c338a5bdd99c2edc24541da0a9262d654e9962
Author: User3 <[email protected]>
Date:   Fri May 26 13:55:52 2017 -0700

    commit3

diff --git a/hello.txt b/hello.txt
index 84a0ce0..b85a64c 100644
--- a/hello.txt
+++ b/hello.txt
@@ -1 +1,2 @@
-Hello     world!
+Hello
+world!

commit fdd9abbe78fdcbbea3f4acf812e2f5e9867e33f1
Author: User2 <[email protected]>
Date:   Fri May 26 13:51:50 2017 -0700

    commit 2

diff --git a/hello.txt b/hello.txt
index cd08755..84a0ce0 100644
--- a/hello.txt
+++ b/hello.txt
@@ -1 +1 @@
-Hello world!
+Hello     world!

commit dd5c453d7788bedc05eb5665b2dc5454d7a83291
Author: User1 <[email protected]>
Date:   Fri May 26 13:50:54 2017 -0700

    Commit 1

diff --git a/hello.txt b/hello.txt
new file mode 100644
index 0000000..cd08755
--- /dev/null
+++ b/hello.txt
@@ -0,0 +1 @@
+Hello world!

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章