git - 在 Git 中使用替代差异算法

标签 git diff

因为 git 是为源代码设计的,它默认的 diff 算法将一行视为最小的不可分割单元。

我正在尝试编辑一些在第 80 列自动换行的 Markdown 文件。添加一个句子可能会导致该段落的其余部分被标记为已更改。

有没有办法让 Git 使用更适合文本的差异算法?我需要一个将单词或句子视为不可分割的单元而不是行的工具吗?

最佳答案

您可以试试 git diff --word-diff

$ git diff --word-diff
diff --git a/test.txt b/test.txt
index 54585bb..a8cd97e 100644
--- a/test.txt
+++ b/test.txt
@@ -1,7 +1,7 @@
Because git is designed for source code, its diff algorithms {+are bibbity +}
{+bobbity boo+} treat a line as the minimum indivisible unit. I am trying to edit 
some markdown files that are word wrapped at column 80. Adding a sentence can 
cause the rest of the paragraph to be marked as changed.

Is there a way to have Git use a diff algorithm more suited to text? One that 
treats words or sentences as indivisible units rather then lines?
 No newline at end of file

关于git - 在 Git 中使用替代差异算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5999495/

相关文章:

GitHub : merging from master back into feature branch

git - 如何仅删除远程存储库中的文件?

linux - Git 中的多平台开发和 autocrlf 选项

java - 根据两个列表的差异创建指令列表

java - 文件比较和突出显示 - Java

svn - Git svn rebase : checksum mismatch

unix - diff'ing diffs with diff?

git - 为什么 git diff 显示修改后的相同文件?

ios - 查找两个对象之间更改的属性

从我 fork 的仓库中 pull 时发生 Git 冲突,即使我做的最后一件事是从中 pull