git diff不支持不区分大小写的文件比较。谷歌显示,只有很少的人要求这一功能,而且这也只能与其他git diff交换机结合使用,比如使用-G或--color-words。
我不关心其他开关,只要git diff能告诉我区分大小写就行了。
因为我没有看到任何具体的问题,而且我在研究这个问题一个小时后找到了解决方案,所以我添加了这个问题和答案。
发布于 2013-06-29 20:19:33
解决方案是使用git difftool。使用以下配置命令,我可以添加一个名为idiff的自定义diff工具供Git使用:
git config --global difftool.idiff.cmd 'diff -i $LOCAL $REMOTE'
通过这种自定义,我可以看到不区分大小写的比较,如下所示:
git difftool --tool idiff <other diff options> <Git references or files>
例如:
git difftool -t idiff HEAD~1 -- my_schema.sql
由于git difftool在每次调用该工具之前都会提示(表示是/否),因此请对difftool使用-y开关或添加此配置选项以避免提示:
git config --global difftool.prompt 0
更新(2021/11/26):这是我使用的统一配置,它允许我使用与git diff行为几乎相同的git idiff命令。
git config --global difftool.idiff.cmd 'diff --unified=3 --color=always --ignore-case $LOCAL $REMOTE | less --raw-control-chars'
git config --global difftool.prompt 0
git config --global alias.idiff 'difftool --tool idiff'发布于 2017-02-28 23:51:14
为了扩展Gurjeet Singh的answer和caw的colordiff comment,在Windows中,我做了以下操作来将它们捆绑在一起:
make版本,所以你也许可以只使用它的make,但你的使用里程可能会有所不同。colordiff Perl脚本。我编辑了Makefile,将安装位置更改为~/bin和~/etc (其中~是%USERPROFILE%),因为~/bin已经在我的PATH中。作为needed..PL添加到PATHEXT (如果是necessary).PATH的任何bin/ )创建一个bash脚本(例如,~/bin/colordiffless.bash),该脚本将任何参数传递给colordiff.pl (colordiff接受diff选项并自动传递它们),并通过less管道。colordiff输出的颜色代码是ANSI,这是cmd.exe不能理解的,但less能理解。还可以通过这种方式恢复Git的分页行为(如有必要,请配置LESS环境变量)。#!/bin/bash colordiff.pl "$@“|更少的
diff,而是调用您的bash脚本。颜色代码的输出是ANSI,所以你需要一些东西来转换它们。我碰巧知道MSYS就是这么做的,而且你也保留了less的寻呼机行为!git配置--全局difftool.cldiff.cmd "colordiffless.bash -ui $LOCAL $REMOTE“
(来自cmd.exe,因此双引号是文字,$LOCAL和$REMOTE是文字文本too)
difftool命令,因此您可以键入单个自定义命令,而不是difftool命令:git配置--全局alias.cldiff "difftool -y -t cldiff"
编辑
我搞错了传呼机的行为又回来了。difftool为每个文件调用该命令,因此您将为每个文件获得一个分页程序,而不是每次diff都获得一个分页程序输出。为了解决这个问题,您可能希望将difftool -y包装在脚本中,并通过管道将其整个输出传递给less。
发布于 2022-01-03 10:10:58
有一点修正--不需要在补丁中有无用的颜色:
git config --global difftool.idiff.cmd 'diff --unified=3 --color=never --ignore-case $LOCAL $REMOTE | less --raw-control-chars'
git config --global difftool.prompt 0
git config --global alias.idiff 'difftool --tool idiff'然后,应该可以通过以下方式生成漂亮的HTML
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8" />
<!-- Make sure to load the highlight.js CSS file before the Diff2Html CSS file -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.7.1/styles/github.min.css" />
<link
rel="stylesheet"
type="text/css"
href="https://cdn.jsdelivr.net/npm/diff2html/bundles/css/diff2html.min.css"
/>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/diff2html/bundles/js/diff2html-ui.min.js"></script>
</head>
<script>
function show(diffString) {
var targetElement = document.getElementById('myDiffElement');
var configuration = {
drawFileList: true,
fileListToggle: false,
fileListStartVisible: false,
fileContentToggle: false,
matching: 'lines',
outputFormat: 'side-by-side',
synchronisedScroll: true,
highlight: true,
renderNothingWhenEmpty: false,
};
var diff2htmlUi = new Diff2HtmlUI(targetElement, diffString, configuration);
diff2htmlUi.draw();
diff2htmlUi.highlightCode();
}
</script>
<body>
<div id="myDiffElement"></div>
<textarea onchange="show(this.value)" rows=30 cols=160></textarea>
</body>
</html>
https://stackoverflow.com/questions/17380029
复制相似问题