Windows 中 diff 命令的等价物是什么?

发布于 2024-11-27 04:08:56 字数 312 浏览 2 评论 0 原文

我知道有一个与此类似的帖子: 这里
我尝试使用上面提到的comp命令,但是如果我有两个文件,一个包含“abcd”等数据,另一个包含“abcde”数据,它只是说这些文件的大小不同。我想知道它们到底有什么不同。在 Unix 中,简单的 diff 告诉我哪一行和哪一列,如果我有像“abd”和“abc”这样的东西,Windows 中的 comp 命令可以工作。不然的话。我可以为此使用什么想法吗?

I know that there is a post similar to this : here.
I tried using the comp command like it mentioned, but if I have two files, one with data like "abcd" and the other with data "abcde", it just says the files are of different sizes. I wanted to know where exactly they differ. In Unix, the simple diff tells me which row and column, the comp command in windows works if I have something like "abd" and "abc". Not otherwise. Any ideas what I can use for this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(13

腻橙味 2024-12-04 04:08:56

在 CMD shell 或批处理文件中运行此命令:

FC file1 file2

FC 也可用于比较二进制文件:

FC /B file1 file2

Run this in the CMD shell or batch file:

FC file1 file2

FC can also be used to compare binary files:

FC /B file1 file2
无妨# 2024-12-04 04:08:56

好吧,在 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 than diff itself!

怪我太投入 2024-12-04 04:08:56

另一种选择是在此处下载并安装 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 your PATH variable. This will give you not only diff, 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 with Git\bin\

Git diff documentation

刘备忘录 2024-12-04 04:08:56

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.

暮倦 2024-12-04 04:08:56

FC 效果很好,但就我而言,它没有帮助,因为我只想要更改的行。 FC 提供附加数据,如文件名、相同行和双边比较。

>fc data.txt data.txt.bak   
***** DATA.TXT
####09
####09
####09
***** DATA.TXT.BAK
####09
####08
####09

但是,就我而言,我只想要已更改的行,并希望将这些行导出到不同的文件,而不需要任何其他标头或数据。

因此,我使用 findstr 来比较文件:

findstr /V /G:data.txt.bak data.txt > DiffResult.txt

其中:

  • 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.

>fc data.txt data.txt.bak   
***** DATA.TXT
####09
####09
####09
***** DATA.TXT.BAK
####09
####08
####09

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:

findstr /V /G:data.txt.bak data.txt > DiffResult.txt

Where:

  • data.txt.bak is the name of old file

  • data.txt is the name of new file

  • DiffResult.txt contains the data that is changed, i.e., just one line: ####09

残龙傲雪 2024-12-04 04:08:56

还有 Powershell(它是 Windows 的一部分)。它并不快,但很灵活,这是基本命令。如果您需要更好的格式,人们已经为其编写了各种 cmdlet 和脚本。

PS C:\Users\Troll> Compare-Object (gc $file1) (gc $file2)

不是 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.

PS C:\Users\Troll> Compare-Object (gc $file1) (gc $file2)

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.

抹茶夏天i‖ 2024-12-04 04:08:56

足球俱乐部fc 比 Cygwin 的 diff 更擅长处理大文件(> 4 GB)。

fc. fc is better at handling large files (> 4 GBytes) than Cygwin's diff.

丘比特射中我 2024-12-04 04:08:56

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.

檐上三寸雪 2024-12-04 04:08:56

COMP 出现错误的原因是该实用程序假定您正在比较的文件具有相同的大小。为了克服这个问题,您可以使用 '/n' 选项来指定要比较的行数。 (通过在命令行上键入 'comp /?' 来查看 comp 支持的选项。
所以你的命令看起来像:

C:\>comp "filepath1" "filepath2" /a /l /n=(the number of lines you want to compare) /c 

如果你想坚持使用 COMP,这应该可以解决你的问题。但这对于非常大的文件来说将是一个问题。

虽然 comp 是一个选项,但我觉得它很原始,而 FC 是一个更好的选择。如果您经常需要一个文件比较实用程序,您可以将 FORFILESFC 一起使用,这可能会成为一个非常好的文件比较实用程序。

FC 以这种方式用于参考:

C:\>fc /c(case insensistive) /lbn(number of errors allowed before you wanna stop compare) /n(display line number) "filename1" "filename2"

有许多可用选项,您可以通过 '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 :

C:\>comp "filepath1" "filepath2" /a /l /n=(the number of lines you want to compare) /c 

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 and FC is a better option. you can use FORFILES and FC together to probably make a really good filecompare utility if you require one on a frequent basis.

FC is used this way for ref:

C:\>fc /c(case insensistive) /lbn(number of errors allowed before you wanna stop compare) /n(display line number) "filename1" "filename2"

there are many options available which you can see by 'fc /?'
hope this helps

清晰传感 2024-12-04 04:08:56

我发现了一个适用于 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

情栀口红 2024-12-04 04:08:56

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/

乖乖 2024-12-04 04:08:56

我不知道以下工具是否正是您所需要的。但我喜欢针对特定文件使用一些在线工具。这样无论操作系统如何我都可以使用它。这是一个示例: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.

美人如玉 2024-12-04 04:08:56

如果您的计算机上安装了 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文