git diff の 差分にだけ ^M が表示される

git diff で変種箇所だけ ^M が付いてるのに気づきました.
編集ミスて改行コードを間違えたかと思ったけど元々 \r\n なファイルで編集箇所以外も同じ \r\n です.
でも非編集箇所は ^M が出ません.


git diff
$ git diff -p
diff --git a/src/onnxstream.cpp b/src/onnxstream.cpp
index 5ace952..bbc62f6 100644
--- a/src/onnxstream.cpp
+++ b/src/onnxstream.cpp
@@ -503,7 +503,7 @@ public:
             throw std::runtime_error("failed to initialize XNNPACK");
     }

-    ~XnnPack()
+    ~XnnPack() noexcept(false)^M (1)
     {
         for (auto& entry : m_ops_cache)
         {
diff --git a/src/onnxstream.h b/src/onnxstream.h
index 6746f61..9c2755a 100644
--- a/src/onnxstream.h
+++ b/src/onnxstream.h
@@ -1,5 +1,6 @@                                                                          e           '
 #pragma once

+#include <algorithm>^M (2)
 #include <limits>
 #include <vector>
 #include <functional>
  1. ここと

  2. ここの編集差分に ^M

od で見ると編集箇所もそれ以外も \r\n になっている
$ head -4 ../../src/onnxstream.h | od -xc
0000000    7023    6172    6d67    2061    6e6f    6563    0a0d    0a0d
          #   p   r   a   g   m   a       o   n   c   e  \r  \n  \r  \n
0000020    6923    636e    756c    6564    3c20    6c61    6f67    6972
          #   i   n   c   l   u   d   e       <   a   l   g   o   r   i
0000040    6874    3e6d    0a0d    6923    636e    756c    6564    3c20
          t   h   m   >  \r  \n   #   i   n   c   l   u   d   e       <
0000060    696c    696d    7374    0d3e    000a
          l   i   m   i   t   s   >  \r  \n
0000071

ということでファイルの内容は問題無さそうですが, git diff の表示上の問題のようです.

検索して以下のページを見つけました.

いろいろな方法が書かれていますが,ちょっと試したいリポジトリなので改行コードを変更するのではなく \M の表示を抑制するようにしたいです.

一番お手軽そうなコマンドラインオプションをいくつか試しましたが以下のオプションはすべて変化が見られませんでした.

git diff のオプション
$ git diff -b
$ git diff --ignore-cr-at-eol
$ git diff --ignore-space-change
$ git diff --ignore-all-space

git-config に whitespace = cr-at-eol を設定してみます. CR/LF のファイルはあまり使うことはないので --local に設定しておきます.

$ git config --local core.whitespace cr-at-eol
$ grep cr-at-eol .git/config
        whitespace = cr-at-eol

この設定をすることで ^M が表示されなくなりました.

$ git diff
diff --git a/src/onnxstream.cpp b/src/onnxstream.cpp
index 5ace952..bbc62f6 100644
--- a/src/onnxstream.cpp
+++ b/src/onnxstream.cpp
@@ -503,7 +503,7 @@ public:
             throw std::runtime_error("failed to initialize XNNPACK");
     }

-    ~XnnPack()
+    ~XnnPack() noexcept(false)
     {
         for (auto& entry : m_ops_cache)
         {
diff --git a/src/onnxstream.h b/src/onnxstream.h
index 6746f61..9c2755a 100644
--- a/src/onnxstream.h
+++ b/src/onnxstream.h
@@ -1,5 +1,6 @@
 #pragma once

+#include <algorithm>
 #include <limits>
 #include <vector>
 #include <functional>
環境
$ git --version
git version 2.45.2
$ dpkg-query -W git
git     1:2.45.2-1
$ lsb_release -dr
Description:    Debian GNU/Linux trixie/sid
Release:        n/a
$ arch
x86_64

コメントを残す

メールアドレスが公開されることはありません。 ※ が付いている欄は必須項目です

Your post must include a link to this post.

How does this work?
Write a response on your own website and include a link to this post. Then submit your response’s URL here. Your response may appear here after moderation. To update or remove it, edit or delete your original post and submit the same URL again. Learn more about Webmentions.