Quantcast
Channel: Make 'git diff' ignore ^M - Stack Overflow
Viewing all articles
Browse latest Browse all 14

Make 'git diff' ignore ^M

$
0
0

In a project where some of the files contain ^M as newlineseparators, diffing these files is apparently impossible, sincegit diff sees the entire file as just a single line.

How does one git diff when comparing the current and previousversions of a source code file?

Is there an option like "treat ^M as newline when diffing" ?

prompt> git-diff "HEAD^" -- MyFile.as diff --git a/myproject/MyFile.as b/myproject/MyFile.asindex be78321..a393ba3 100644--- a/myproject/MyFile.cpp+++ b/myproject/MyFile.cpp@@ -1 +1 @@-<U+FEFF>import flash.events.MouseEvent;^Mimport mx.controls.*;^Mimport mx.utils.Delegate\ No newline at end of file+<U+FEFF>import flash.events.MouseEvent;^Mimport mx.controls.*;^Mimport mx.utils.Delegate\ No newline at end of fileprompt>

UPDATE:

I have written a Ruby script that checks out the latest 10 revisions and converts CR to LF.

require 'fileutils'if ARGV.size != 3  puts "a git-path must be provided"  puts "a filename must be provided"  puts "a result-dir must be provided"  puts "example:"  puts "ruby gitcrdiff.rb project/dir1/dir2/dir3/ SomeFile.cpp tmp_somefile"  exit(1)endgitpath = ARGV[0]filename = ARGV[1]resultdir = ARGV[2]unless FileTest.exist?(".git")  puts "this command must be run in the same dir as where .git resides"  exit(1)endif FileTest.exist?(resultdir)  puts "the result dir must not exist"  exit(1)endFileUtils.mkdir(resultdir)10.times do |i|  revision = "^" * i  cmd = "git show HEAD#{revision}:#{gitpath}#{filename} | tr '\\r''\\n'> #{resultdir}/#{filename}_rev#{i}"  puts cmd   system cmdend

Viewing all articles
Browse latest Browse all 14

Latest Images

Trending Articles





Latest Images