Why does sed cause git to consider the entire file rewritten?

3

Using Cygwin on Win7x32, when I use sed to replace some values in a file, git then considers the entire file to be completely rewritten (i.e., 500 insertions, 500 deletions). What's going on here? Only one line in the file is actually changed, and the replacement value is the same length as the original. I'd expect git to recognize only the lines that changed. The only thing that seems to have changed at all is the inode and time values as read from stat some/file.txt. Is there a way to tell git to ignore any relevant changed values for the duration of my sed calls, or to tell sed to not change any values that cause git to see a file with entirely new content?

wes

Posted 2012-03-06T17:54:54.620

Reputation: 645

Answers

6

I don't work with Windows much, but perhaps sed is changing your end-of-line markers. The file command will tell you which text encoding is being used. Also, you can run cat -e before and after you call sed; if the file is encoded for Windows each line will end with ^M.

eduffy

Posted 2012-03-06T17:54:54.620

Reputation: 641

Using unix2dos helped, however somehow, now I have only replaced line ending in ^M, the rest is still LF. – VsMaX – 2016-10-21T05:55:51.730

1This looks like the culprit; before, the file is ASCII C++ program text, with CRLF line terminators, and after, ASCII C++ program text. I was under the impression that sed didn't do any sort of automagical conversions like that, being a "stream editor," but oh well. – wes – 2012-03-06T18:41:43.487

Does cygwin have the unix2dos tool? That'll put back the Windows end-of-line marker. – eduffy – 2012-03-06T18:51:09.153

Yep, that's what I ended up using. Just a little surprised after hearing so many good things about sed. – wes – 2012-03-06T18:52:08.247