如何使用 meld 作为您的 git difftool 代替 git diff(另请参阅下面的 meld 屏幕截图):
1。窗户:
下载并安装Git for Windows,其中包括一个类似于“Git Bash”的 Linux 终端,可通过 Windows 资源管理器中任何文件夹中的右键菜单访问,一旦您安装了适用于 Windows 的 Git。
从这里下载并安装 meld:https://meldmerge.org/。
然后,要使 meld 成为您的 git difftool,您可以在 Git for Windows bash 终端 (as Arugin says) 中使用这两个命令,并使用正确的 Meld.exe 路径:
git config --global merge.tool meld
git config --global mergetool.meld.path "C:\Program Files (x86)\Meld\Meld.exe"
或者您可以直接编辑您的C:\Users\YOUR_USER_NAME\.gitconfig 文件并将以下内容添加到它的末尾(注意这里强制使用双反斜杠 [\\] 作为路径分隔符!):
[merge]
tool = meld
[mergetool "meld"]
path = C:\\Program Files (x86)\\Meld\\Meld.exe
现在在您的Git for Windows bash 终端中调用git difftool,Meld 将作为您的默认 difftool 查看器打开!如果您还不知道:您可以通过右键单击 Windows 资源管理器中的文件夹并转到 --> "Git Bash" 或其他任何名称来在 Windows 中打开所述终端。
2。 Linux:
如果没有别的,我不妨把 Linux 说明也放在这里供我自己参考:
对于 Linux,它更容易:
# 1. install meld
sudo apt update
sudo apt install meld
# 2. edit your ~/.gitconfig file (gedit GUI editor will open)
gedit ~/.gitconfig
然后在.gitconfig文件的底部添加:
[diff]
tool = meld
就是这样! git difftool 现在可以在 Linux Ubuntu 上运行!
3。 Mac 操作系统
在 Mac OS 上安装 Meld:https://superuser.com/questions/360007/how-to-install-meld-with-homebrew-on-mac-osx/1177575#1177575。
Meld 截图示例
(source)
Meld 的使用
# 1. See changes you've made since your last commit (do this in place of
# `git diff`)
git difftool
# 2. Calling meld directly to compare two files:
meld path/to/file1.txt path/to/file2.txt
使用meld在您的机器上本地查看其他人的 GitHub PR
注意:以下命令假定它们的分支位于您的同一个代码仓库中,因为您是队友。如果不是这种情况,您将不得不稍微修改命令以从他们的分叉存储库而不是从您的公共存储库中签出。当在线查看 PR 时,GitHub 会向您展示他们推荐的用于检查其分支的命令。
- 仅命令
git fetch origin someone_elses_branch
git checkout someone_elses_branch
git difftool main...HEAD # 3 dots, NOT 2!
- 带有详细 cmets 的命令
# 1. Fetch their remote changes to your local machine into your
# locally-stored,remote-tracking hidden branch named
# `origin/someone_elses_branch`
git fetch origin someone_elses_branch
# 2. Check out this branch locally (this creates the locally-stored branch
# named `someone_elses_branch` from the locally-stored remote-tracking
# hidden branch named `origin/someone_elses_branch`)
git checkout someone_elses_branch
# 3. Do a difftool comparison (using meld now) to see the changes
# made on this branch from the point where they last checked out
# and forked off of `main`. This cmd (using 3 dots) is the equivalent of
# `git difftool $(git merge-base main HEAD) HEAD`.
git difftool main...HEAD # 3 dots, NOT 2!
相关:
- 3 点 vs 2 点:What are the differences between double-dot ".." and triple-dot "..." in Git diff commit ranges?
- [我在
git blametool 上的回答] Is there git blame gui similar to bzr qannotate?
- 从这里下载并安装 meld:https://meldmerge.org/
- [我的回答]How do I make Git use the editor of my choice for commits?
- [我的仓库]https://github.com/ElectricRCAircraftGuy/eRCaGuy_dotfiles
- 在 Mac OS 上安装 Meld:https://superuser.com/questions/360007/how-to-install-meld-with-homebrew-on-mac-osx/1177575#1177575