Windows 中 diff 命令的等价物是什么?
我知道有一个与此类似的帖子: 这里。
我尝试使用上面提到的comp命令,但是如果我有两个文件,一个包含“abcd”等数据,另一个包含“abcde”数据,它只是说这些文件的大小不同。我想知道它们到底有什么不同。在 Unix 中,简单的 diff 告诉我哪一行和哪一列,如果我有像“abd”和“abc”这样的东西,Windows 中的 comp 命令可以工作。不然的话。我可以为此使用什么想法吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(13)
在 CMD shell 或批处理文件中运行此命令:
FC
也可用于比较二进制文件:Run this in the CMD shell or batch file:
FC
can also be used to compare binary files:好吧,在 Windows 上我很高兴运行
diff
和许多其他 GNU 工具。你可以使用 cygwin 来完成,但我个人更喜欢 GnuWin32 因为它的安装体验要轻得多。所以,我的答案是 Windows 中的
diff
等价物正是diff
本身!Well, on Windows I happily run
diff
and many other of the GNU tools. You can do it with cygwin, but I personally prefer GnuWin32 because it is a much lighter installation experience.So, my answer is that the Windows equivalent of
diff
, is none other thandiff
itself!另一种选择是在此处下载并安装 git。然后你有 2 个选项:
选项 1(首选)
使用 Git Bash 中的 diff(从上面安装)并像 Windows 上的本机 *nix 用户一样愉快地进行 diff。
选项 2
将
Git\bin\
的路径(或'C:\Program Files\Git\usr\bin\'
)添加到您的PATH
变量。这不仅会为您提供diff
,还会为您提供许多其他可以从 Windows 命令行使用的 Linux 命令。您可以通过右键单击“计算机”并选择“属性”来设置
PATH
变量。然后您可以单击屏幕左侧的高级系统设置。在弹出窗口中,单击“环境变量”,然后使用Git\bin\
添加或更新用户变量中的 PATH 变量Git diff 文档
Another alternative is to download and install git here. Then you have 2 options:
Option 1 (preferred)
Use diff from Git Bash(installed from above) and diff happily like a native *nix user on Windows.
Option 2
Add the path to
Git\bin\
(or'C:\Program Files\Git\usr\bin\'
) to yourPATH
variable. This will give you not onlydiff
, but also many other Linux commands that you can use from the Windows command line.You can set the
PATH
variable by right clicking on Computer and selecting Properties. Then you can click on Advanced System Settings on the left side of the screen. In the pop up, click Environment Variables and then either add or update the PATH variable in your user variables withGit\bin\
Git diff documentation
Winmerge 有一个命令行实用程序,可能值得一试。
此外,您也可以根据需要使用它的图形部分。
Winmerge has a command line utility that might be worth checking out.
Also, you can use the graphical part of it too depending on what you need.
FC 效果很好,但就我而言,它没有帮助,因为我只想要更改的行。 FC 提供附加数据,如文件名、相同行和双边比较。
但是,就我而言,我只想要已更改的行,并希望将这些行导出到不同的文件,而不需要任何其他标头或数据。
因此,我使用
findstr
来比较文件:其中:
data.txt.bak
是旧文件的名称data.txt
是新文件的名称DiffResult.txt
包含更改的数据,即只有一行:####09
FC works great but, in my case, it was not helpful as I wanted just the lines that are changed. And FC gives additional data like file name, same lines and bilateral comparison.
But, in my case, I wanted only the lines that have changed and wanted those lines to be exported to a different file, without any other header or data.
So, I used
findstr
to compare the files:Where:
data.txt.bak
is the name of old filedata.txt
is the name of new fileDiffResult.txt
contains the data that is changed, i.e., just one line:####09
还有 Powershell(它是 Windows 的一部分)。它并不快,但很灵活,这是基本命令。如果您需要更好的格式,人们已经为其编写了各种 cmdlet 和脚本。
不是 Windows 的一部分,但如果您是 Visual Studio 的开发人员,它会附带 WinDiff(图形),
但我个人最喜欢的是 BeyondCompare,售价 30 美元。
There's also Powershell (which is part of Windows). It ain't quick but it's flexible, here's the basic command. People have written various cmdlets and scripts for it if you need better formatting.
Not part of Windows, but if you are a developer with Visual Studio, it comes with WinDiff (graphical)
But my personal favorite is BeyondCompare, which costs $30.
足球俱乐部fc 比 Cygwin 的 diff 更擅长处理大文件(> 4 GB)。
fc. fc is better at handling large files (> 4 GBytes) than Cygwin's diff.
DiffUtils 可能是您最好的选择。它相当于 Windows 中的 diff。
据我所知,没有内置的等效项。
DiffUtils is probably your best bet. It's the Windows equivalent of diff.
To my knowledge there are no built-in equivalents.
COMP 出现错误的原因是该实用程序假定您正在比较的文件具有相同的大小。为了克服这个问题,您可以使用
'/n'
选项来指定要比较的行数。 (通过在命令行上键入'comp /?'
来查看 comp 支持的选项。所以你的命令看起来像:
如果你想坚持使用 COMP,这应该可以解决你的问题。但这对于非常大的文件来说将是一个问题。
虽然
comp
是一个选项,但我觉得它很原始,而FC
是一个更好的选择。如果您经常需要一个文件比较实用程序,您可以将FORFILES
和FC
一起使用,这可能会成为一个非常好的文件比较实用程序。FC 以这种方式用于参考:
有许多可用选项,您可以通过
'fc /?'
查看希望这有帮助
The reason you getting the error with COMP is that the utility assumes the files that you are comparing are of the same size. To overcome that you can use th
'/n'
option with which you can specify the number of lines you want to compare. (see the options supported by comp by typing'comp /?'
on the command line.so your command would look like :
This should solve your problem if you wanna stick to using COMP. But this will be a problem for really large files.
Though
comp
is an option, but I feel it is primitive andFC
is a better option. you can useFORFILES
andFC
together to probably make a really good filecompare utility if you require one on a frequent basis.FC is used this way for ref:
there are many options available which you can see by
'fc /?'
hope this helps
我发现了一个适用于 Windows 的轻量级图形软件,在缺少
diff
命令的情况下似乎很有用。它可以解决我所有的问题。WinDiff http://www.grigsoft.com/download-windiff。嗯
I've found a lightweight graphical software for windows that seems to be useful in lack of
diff
command. It could solve all of my problems.WinDiff http://www.grigsoft.com/download-windiff.htm
windows中相当于diff命令的是fc(File Comapre)命令。
以下是执行此操作的基本步骤:
1. 将两个文件保存在一个文件夹中(示例 file1.html 和 file2.html)
2.启动命令提示符
3. 输入 fc file1Location file2Location
已找到相同的详细教程:
http://www.howtogeek.com/206123/how-to-use-fc-file-compare-from-the-windows-command-prompt/
The windows equivalent to the diff command is the fc (File Comapre) command.
Here are the basic steps to do so:
1. Keep the two files in a folder (Example file1.html and file2.html)
2. Launch command prompt
3. Type fc file1Location file2Location
Have found a detailed tutorial on the same:
http://www.howtogeek.com/206123/how-to-use-fc-file-compare-from-the-windows-command-prompt/
我不知道以下工具是否正是您所需要的。但我喜欢针对特定文件使用一些在线工具。这样无论操作系统如何我都可以使用它。这是一个示例:diffchecker.com
但对于我的需要,我认为跟踪项目文件更改和日志的最佳工具是 GIT。如果您在团队中工作,您可以在自己的服务器上在线存储一些存储库,或者将其与 Bitbucket 或 Github 一起使用。
希望它对某人有帮助。
I don't know if the following tool is exatly what you need. But I like to use, for specific files, some online tool. This way I can use it regardless of the operational system. Here is a example: diffchecker.com
But for my needs, I guess the best tool to track changes and logs of my project's files is GIT. If you work in a team, you can have some repo online in a server of yours, or use it with Bitbucket or Github.
Hope it helps somebody.
如果您的计算机上安装了 git,则可以打开 git 终端并正常使用 Linux
diff
命令。If you have installed git on your machine, you can open a git terminal and just use the Linux
diff
command as normal.