Merge pull request #17921 from geekpi/translating

translated
This commit is contained in:
geekpi 2020-03-30 08:37:32 +08:00 committed by GitHub
commit ced9e19436
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 129 additions and 131 deletions

View File

@ -1,131 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Don't love diff? Use Meld instead)
[#]: via: (https://opensource.com/article/20/3/meld)
[#]: author: (Ben Nuttall https://opensource.com/users/bennuttall)
Don't love diff? Use Meld instead
======
Meld is a visual diff tool that makes it easier to compare and merge
changes in files, directories, Git repos, and more.
![Person drinking a hat drink at the computer][1]
Meld is one of my essential tools for working with code and data files. It's a graphical diff tool, so if you've ever used the **diff** command and struggled to make sense of the output, [Meld][2] is here to help.
Here is a brilliant description from the project's website:
> "Meld is a visual diff and merge tool targeted at developers. Meld helps you compare files, directories, and version controlled projects. It provides two- and three-way comparison of both files and directories, and has support for many popular version control systems.
>
> "Meld helps you review code changes and understand patches. It might even help you to figure out what is going on in that merge you keep avoiding."
You can install Meld on Debian/Ubuntu systems (including Raspbian) with:
```
`$ sudo apt install meld`
```
On Fedora or similar, it's:
```
`$ sudo dnf install meld`
```
Meld is cross-platform—there's a [Windows install][3] using the [Chocolately][4] package manager. While it's not officially supported on macOS, there are [builds available for Mac][5], and you can install it on Homebrew with:
```
`$ brew cask install meld`
```
See Meld's homepage for [additional options][2].
### Meld vs. the diff command
If you have two similar files (perhaps one is a modified version of the other) and want to see the changes between them, you could run the **diff** command to see their differences in the terminal:
![diff output][6]
This example shows the differences between **conway1.py** and **conway2.py**. It's showing that I:
* Removed the [shebang][7] and second line
* Removed **(object)** from the class declaration
* Added a docstring to the class
* Swapped the order of **alive** and **neighbours == 2** in a method
Here's the same example using the **meld** command. You can run the same comparison from the command line with:
```
`$ meld conway1.py conway2.py`
```
![Meld output][8]
Much clearer!
You can easily see changes and merge changes between files by clicking the arrows (they work both ways). You can even edit the files live (Meld doubles up as a simple text editor with live comparisons as you type)—just be sure to save before you close the window.
You can even compare and edit three different files:
![Comparing three files in Meld][9]
### Meld's Git-awareness
Hopefully, you're using a version control system like [Git][10]. If so, your comparison isn't between two different files but to find differences between the current working file and the one Git knows. Meld understands this, so if you run **meld conway.py**, where **conway.py** is known by Git, it'll show you any changes made since the last Git commit:
![Comparing Git files in Meld][11]
You can see changes made in the current version (on the right) and the repository version (on the left). You can see I deleted a method and added a parameter and a loop since the last commit.
If you run **meld .**, you'll see all the changes in the current directory (or the whole repository, if you're in its root):
![Meld . output][12]
You can see a single file is modified, another file is unversioned (meaning it's new to Git, so I need to **git add** the file before comparing it), and lots of other unmodified files. Various display options are provided by icons along the top.
You can also compare two directories, which is sometimes handy:
![Comparing directories in Meld][13]
### Conclusion
Even regular users can find comparisons with diff difficult to decipher. I find the visualizations Meld provides make a big difference in troubleshooting what's changed between files. On top of that, Meld comes with some helpful awareness of version control and helps you compare across Git commits without thinking much about it. Give Meld a go, and make troubleshooting a little easier on the eyes.
* * *
_This was originally published on Ben Nuttall's [Tooling blog][14] and is reused with permission._
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/3/meld
作者:[Ben Nuttall][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/bennuttall
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/coffee_tea_laptop_computer_work_desk.png?itok=D5yMx_Dr (Person drinking a hat drink at the computer)
[2]: https://meldmerge.org/
[3]: https://chocolatey.org/packages/meld
[4]: https://opensource.com/article/20/3/chocolatey
[5]: https://yousseb.github.io/meld/
[6]: https://opensource.com/sites/default/files/uploads/diff-output.png (diff output)
[7]: https://en.wikipedia.org/wiki/Shebang_(Unix)
[8]: https://opensource.com/sites/default/files/uploads/meld-output.png (Meld output)
[9]: https://opensource.com/sites/default/files/uploads/meld-3-files.png (Comparing three files in Meld)
[10]: https://opensource.com/resources/what-is-git
[11]: https://opensource.com/sites/default/files/uploads/meld-git.png (Comparing Git files in Meld)
[12]: https://opensource.com/sites/default/files/uploads/meld-directory-changes.png (Meld . output)
[13]: https://opensource.com/sites/default/files/uploads/meld-directory-compare.png (Comparing directories in Meld)
[14]: https://tooling.bennuttall.com/meld/

View File

@ -0,0 +1,129 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Don't love diff? Use Meld instead)
[#]: via: (https://opensource.com/article/20/3/meld)
[#]: author: (Ben Nuttall https://opensource.com/users/bennuttall)
不喜欢 diff 么?试试 Meld 吧
======
Meld 是一个可视化 diff 工具它可让你轻松比较和合并文件、目录、Git 仓库等的更改。
![Person drinking a hat drink at the computer][1]
Meld 是我处理代码和数据文件的基本工具之一。它是一个图形化的 diff 工具,因此,如果你曾经使用过 **diff** 命令并难以理解输出,那么 [Meld][2] 可以为你提供帮助。
这是该项目网站的精彩描述:
>“ Meld 是面向开发人员的可视化 diff 和合并工具。Meld 帮助你比较文件、目录和版本控制的项目。它提供文件和目录的双向和三向比较,并支持许多流行的版本控制系统。“
>
>“ Meld 帮助你检查代码更改并了解补丁。它甚至可以帮助你弄清你一直在避免的合并中发生了什么。”
你可以使用以下命令在 Debian/Ubuntu 系统(包括 Raspbian上安装 Meld
```
`$ sudo apt install meld`
```
在 Fedora 或类似产品上,是:
```
`$ sudo dnf install meld`
```
Meld 是跨平台的,它有一个使用 [Chocolately][4] 包管理器的 [Windows 安装包][3]。尽管它在 macOS 上不受官方支持,但有[可用于 Mac 的版本][5],你可以使用 Homebrew 安装:
```
`$ brew cask install meld`
```
有关[其他系统][2],请参见 Meld 的主页。
### Meld 对比 diff 命令
如果你有两个相似的文件(也许一个是另一个的修改版本),并想要查看它们之间的更改,那么可以在终端中运行 **diff** 命令查看它们的区别:
![diff output][6]
此例显示了 **conway1.py****conway2.py** 之间的区别。表明我:
* 删除了 [shebang][7] 和第二行
  * 从类声明中删除了 **(object)**
  * 为类添加了 docstring
  * 在方法中交换了 **alive** 和 **neighbours == 2** 的顺序
这是使用 **meld** 命令的相同例子。你可以在命令行中运行以下命令进行相同的比较:
```
`$ meld conway1.py conway2.py`
```
![Meld output][8]
Meld 更清晰!
你可以单击箭头上下都行轻松查看并合并文件之间的更改。你甚至可以实时编辑文件在输入时Meld 可以用作具有实时比较功能的简单文本编辑器)—仅在关闭窗口之前一定要保存。
你甚至可以比较和编辑三个不同的文件:
![Comparing three files in Meld][9]
### Meld 的 Git 认知
希望你正在使用 [Git][10] 之类的版本控制系统。如果是这样,那么你的比较不是在两个不同文件之间进行,而是要查找当前文件与 Git 历史文件之间的差异。Meld 理解这一点,因此,如果你运行 **meld conway.py**Git 中有 **conway.py**),它将显示自上次 Git 提交以来所做的更改:
![Comparing Git files in Meld][11]
你可以看到当前版本(右侧)和仓库版本(左侧)之间的更改。你可以看到,自上次提交以来,我删除了一个方法,并添加了一个参数和一个循环。
如果你运行 **meld .**,你将看到当前目录(如果位于根目录,就是整个仓库)中的所有更改:
![Meld . output][12]
你会看到一个文件被修改,另一个文件未加入版本控制(这意味着它对 Git 是新的,因此在比较之前,我需要 **git add** 该文件),以及许多其他未修改的文件。顶部的图标提供了各种显示选项。
你还可以比较两个目录,这有时很方便:
![Comparing directories in Meld][13]
### 结论
即使是普通用户也会觉得 diff 的比较难以理解。我发现 Meld 提供的可视化在找出文件之间的更改方面有很大的不同。最重要的是Meld 有一些有用的版本控制认知,可以帮助你在不考虑太多内容的情况下对 Git 提交进行比较。快来试试 Meld并轻松解决问题。
* * *
_本文最初发表在 Ben Nuttall 的 [Tooling blog][14] 上并经允许重新使用。_
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/3/meld
作者:[Ben Nuttall][a]
选题:[lujun9972][b]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/bennuttall
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/coffee_tea_laptop_computer_work_desk.png?itok=D5yMx_Dr (Person drinking a hat drink at the computer)
[2]: https://meldmerge.org/
[3]: https://chocolatey.org/packages/meld
[4]: https://opensource.com/article/20/3/chocolatey
[5]: https://yousseb.github.io/meld/
[6]: https://opensource.com/sites/default/files/uploads/diff-output.png (diff output)
[7]: https://en.wikipedia.org/wiki/Shebang_(Unix)
[8]: https://opensource.com/sites/default/files/uploads/meld-output.png (Meld output)
[9]: https://opensource.com/sites/default/files/uploads/meld-3-files.png (Comparing three files in Meld)
[10]: https://opensource.com/resources/what-is-git
[11]: https://opensource.com/sites/default/files/uploads/meld-git.png (Comparing Git files in Meld)
[12]: https://opensource.com/sites/default/files/uploads/meld-directory-changes.png (Meld . output)
[13]: https://opensource.com/sites/default/files/uploads/meld-directory-compare.png (Comparing directories in Meld)
[14]: https://tooling.bennuttall.com/meld/