2012-05-07 42 views

Trả lời

29

Sử dụng --word-diff-regex:

--word-diff-regex=<regex> 
     Use <regex> to decide what a word is, instead of considering runs 
     of non-whitespace to be a word. Also implies --word-diff unless it 
     was already enabled. 

     Every non-overlapping match of the <regex> is considered a word. 
     Anything between these matches is considered whitespace and 
     ignored(!) for the purposes of finding differences. You may want to 
     append |[^[:space:]] to your regular expression to make sure that 
     it matches all non-whitespace characters. A match that contains a 
     newline is silently truncated(!) at the newline. 

     The regex can also be set via a diff driver or configuration 
     option, see gitattributes(1) or git-config(1). Giving it explicitly 
     overrides any diff driver or configuration setting. Diff drivers 
     override configuration settings. 

tôi không bao giờ sử dụng nó, nhưng tôi đoán rằng git diff --word-diff-regex="[^[:space:],]+" có thể làm việc.

+0

Nó không làm việc :-) – oberlies

+0

Bất kỳ ý tưởng làm thế nào để thiết lập nó trong cấu hình git, sử dụng regex này theo mặc định, khi tôi chỉ định --word-diff hơn là tôi phải chỉ định regex mỗi lần . – sibaz

+1

Đã trả lời câu hỏi của riêng tôi: 'git config --global diff.wordRegex [^ [: space:],] +' – sibaz

1

Bạn cũng có thể thử -w/--ignore-all-space, mặc dù điều đó có thể bỏ qua nhiều khoảng trắng hơn bạn muốn.

+0

-b bỏ qua một khoảng trắng ít hơn một chút –

9

Ngoài câu trả lời của KurzedMetal: không có dấu ngoặc kép, nó hoạt động tốt hơn vì nó không phá vỡ tự động hoàn thành bash của tôi khi nhấn TAB.

git diff --word-diff-regex=[^[:space:],]+

Các vấn đề liên quan