使用 vimdiff 查看所有 `git diffs`

发布于 2024-09-19 06:28:07 字数 531 浏览 5 评论 0 原文

我使用 "git diff 来包装到 vimdiff 中“noreferrer">Git Diff with Vimdiff”作为指导,除非有很多文件发生更改,否则它会按预期工作。

当有多个文件发生更改并且我运行 git diff 时,它会打开第一个文件,并且在退出 vimdiff 的第一个实例后,我会看到以下消息:

external diff died, stopping at filename

这是完全不同的行为比我习惯的。我过去在 SVN 上有过类似的设置,当比较多个文件时,我会检查第一个文件,然后使用 :wq 写入并退出,然后会打开下一个有差异的文件。

Git 的情况并非如此。我尝试了 :n[ext],但这样做不会用原始文件填充左侧窗口,以便可以将其与修改后的版本进行比较。

I setup git diff to wrap into vimdiff, using "Git Diff with Vimdiff" as a guide, and it's working as expected unless there are many files with changes.

When there are multiple files with changes and I run git diff, it opens the first file and, after quitting the first instance of vimdiff, I'm presented with the following message:

external diff died, stopping at filename

This is a completely different behavior than I am used to. I had a similar setup in the past with SVN and, when diffing against multiple files, I would review the first file, then write and quit using :wq and the next file with differences would open up.

This is not the case with Git. I tried :n[ext], but doing so does not fill the left window with the original file so that it can be diffed against the modified version.

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

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

发布评论

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

评论(5

青朷 2024-09-26 06:28:07
git config --global diff.tool vimdiff
git config --global difftool.prompt false

输入 git difftool 会产生预期的行为。

vim 中的导航命令

  • :qa 循环到变更集中的下一个文件,而不保存任何内容。

别名(示例)

git config --global alias.d difftool

.. 将让您输入 git d 来调用 vimdiff。

高级用例,

  • 默认情况下,git 使用 -R 选项调用 vimdiff。您可以使用 git config --global difftool.vimdiff.cmd 'vimdiff "$LOCAL" "$REMOTE"' 覆盖它。这将以可写模式打开 vimdiff,允许在比较时进行编辑。
  • vim 中的 :wq 循环到变更集中的下一个文件并保存更改。
git config --global diff.tool vimdiff
git config --global difftool.prompt false

Typing git difftool yields the expected behavior.

Navigation commands,

  • :qa in vim cycles to the next file in the changeset without saving anything.

Aliasing (example)

git config --global alias.d difftool

.. will let you type git d to invoke vimdiff.

Advanced use-cases,

  • By default, git calls vimdiff with the -R option. You can override it with git config --global difftool.vimdiff.cmd 'vimdiff "$LOCAL" "$REMOTE"'. That will open vimdiff in writeable mode which allows edits while diffing.
  • :wq in vim cycles to the next file in the changeset with changes saved.
与往事干杯 2024-09-26 06:28:07

你可以尝试 git difftool ,它就是为了做这些事情而设计的。

首先,你需要将 diff 工具配置为 vimdiff

git config diff.tool vimdiff

然后,当你想要 diff 时,只需使用 git difftool 代替 git diff 即可。它将按您的预期工作。

You can try git difftool, it is designed to do this stuff.

First, you need to config diff tool to vimdiff

git config diff.tool vimdiff

Then, when you want to diff, just use git difftool instead of git diff. It will work as you expect.

习ぎ惯性依靠 2024-09-26 06:28:07
Git accepts kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge,
and opendiff as valid diff tools. You can also set up a custom tool. 

git config --global diff.tool vimdiff
git config --global diff.tool kdiff3
git config --global diff.tool meld
git config --global diff.tool xxdiff
git config --global diff.tool emerge
git config --global diff.tool gvimdiff
git config --global diff.tool ecmerge
Git accepts kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge,
and opendiff as valid diff tools. You can also set up a custom tool. 

git config --global diff.tool vimdiff
git config --global diff.tool kdiff3
git config --global diff.tool meld
git config --global diff.tool xxdiff
git config --global diff.tool emerge
git config --global diff.tool gvimdiff
git config --global diff.tool ecmerge
十二 2024-09-26 06:28:07

如果你想永久使用vimdiff进行git diff,可以设置~/.gitconfig文件:

git config --global diff.tool vimdiff

然后就可以使用 git difftool 来比较。

如果你只想暂时使用 vimdiff,可以每次运行命令:

git difftool --tool=vimdiff

If you want to permanently use vimdiff for git diff, you can set the ~/.gitconfig file:

git config --global diff.tool vimdiff

and then you can use git difftool to diff.

If you only want to temporarily use vimdiff, you can run the command every time:

git difftool --tool=vimdiff
世界等同你 2024-09-26 06:28:07

对于想要使用 git 中未列出的其他 diff 工具的人,可以使用 nvim。这是我最终使用的:

git config --global alias.d difftool -x <tool name>

在我的例子中,我将 设置为 nvim -d 并使用 diff 命令调用

git d <file>

For people who want to use another diff tool not listed in git, say with nvim. here is what I ended up using:

git config --global alias.d difftool -x <tool name>

In my case, I set <tool name> to nvim -d and invoke the diff command with

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