Linux 如何在 svn 中以 vimdiff 样式查看 svn diff

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7866286/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 06:49:49  来源:igfitidea点击:

How to view svn diff in vimdiff style in svn

linuxsvnunixvim

提问by xyz

I am starting to use Subversion on Linux. svn diffgives a very cryptic view—very, very unfriendly to eyes. How do I interpret its output? And more importantly, is there a way to view the difference in vimdiff kind of neat style, where both files will open side by side?

我开始在 Linux 上使用 Subversion。svn diff给出了一个非常神秘的观点——对眼睛非常非常不友好。我如何解释它的输出?更重要的是,有没有一种方法可以查看 vimdiff 那种简洁风格的差异,其中两个文件将并排打开?

采纳答案by xyz

Found it at: http://blog.tplus1.com/index.php/2007/08/29/how-to-use-vimdiff-as-the-subversion-diff-tool/

在以下位置找到它:http: //blog.tplus1.com/index.php/2007/08/29/how-to-use-vimdiff-as-the-subversion-diff-tool/

This blog post takes the script directly from the SVN book external diff tools example:

这篇博文直接从SVN book external diff tools example 中获取脚本:

diffwrap.sh

diffwrap.sh

#!/bin/sh

# Configure your favorite diff program here.
DIFF="/usr/local/bin/vimdiff"

# Subversion provides the paths we need as the sixth and seventh 
# parameters.
LEFT=
RIGHT=

# Call the diff command (change the following line to make sense for
# your merge program).
$DIFF $LEFT $RIGHT

# Return an errorcode of 0 if no differences were detected, 1 if some were.
# Any other errorcode will be treated as fatal.

Note:This assumes that your vimdiffis in /usr/local/bin, for me, in Fedora, it was in /usr/bin. If you can't find it run:

注:这是假设你的vimdiff就是在/usr/local/bin,对我来说,在Fedora中,有人在/usr/bin。如果找不到,请运行:

$ whereis vimdiff

Then in ~/.subversion/config:

然后在~/.subversion/config

[helpers]
...
diff-cmd = /home/<username>/bin/diffwrap.sh

回答by Richard Pennington

I use tkdiff and tkcvs for svn. Nice side by side view.

我将 tkdiff 和 tkcvs 用于 svn。漂亮的并排视图。

回答by Idan Arye

VCSCommandcan do it for you - install the plugin, navigate to the file, and press <Leader>cv

VCSCommand可以为您完成 - 安装插件,导航到文件,然后按<Leader>cv

回答by Ashwinee K Jha

The base of each file is stored in .svn folder so you can write small script to launch vimdiff or mgdiff to give a path in .svn folder against which to compare your file. This won't require you to make vimdiff default diff command for svn.

每个文件的基础都存储在 .svn 文件夹中,因此您可以编写小脚本来启动 vimdiff 或 mgdiff 以在 .svn 文件夹中提供一个路径,以便与您的文件进行比较。这不需要您为 svn 制作 vimdiff 默认 diff 命令。

回答by Omer Dagan

Edit the file $HOME/.subversion/configso it contains the line:

编辑文件$HOME/.subversion/config,使其包含以下行:

diff-cmd = <your favorite diff application>

Some diff apps support svn. For example, diff-cmd = meldshould work fine. However, vimdiffis notone of them. The reason for that is that svn diffgives the files to be compared as 6th and 7th arguments, and not as 1st and 2nd as usual. So what most people do in this situation is this:

一些差异应用程序支持 svn。例如,diff-cmd = meld应该可以正常工作。然而,vimdiff不是其中之一。这样做的原因是svn diff将要比较的文件作为第 6 个和第 7 个参数,而不是像往常一样作为第 1 个和第 2 个参数。所以在这种情况下,大多数人的做法是这样的:

Create a wrapper script:

创建一个包装脚本

#!/bin/sh

/usr/bin/vimdiff  

Save it, for example, at $HOME/bin/svndiffwrap.sh

例如,将其保存在 $HOME/bin/svndiffwrap.sh

Do not forget to make it executable chmod +x $HOME/bin/svndiffwrap.sh.

不要忘记使其可执行chmod +x $HOME/bin/svndiffwrap.sh

Make it the svn diff command:

使其成为 svn diff 命令

in $HOME/.subversion/config:

$HOME/.subversion/config

diff-cmd = /home/<username>/bin/svndiffwrap.sh

Note: Some svn clients do not support paths that uses $HOMEenvironment variable. So it is useful to specify full path.

注意:某些 svn 客户端不支持使用$HOME环境变量的路径。所以指定完整路径很有用。

回答by Brenden

vimdiff <(svn diff)

vimdiff <(svn diff)

<()is referred to as process substitutionwhich creates a pseudo file from the output of svn difffor vimdiffto consume.

<()被称为进程替换,它从svn difffor的输出创建一个伪文件以供vimdiff使用。

You can create a shell alias like so: alias svndiff='vimdiff <(svn diff)'

您可以像这样创建一个 shell 别名: alias svndiff='vimdiff <(svn diff)'

Similar answer

类似的答案

PS - this is the simplest solution I have yet to find; it changed my life (relatively speaking)!

PS - 这是我还没有找到的最简单的解决方案;它改变了我的生活(相对而言)!

回答by Thushan

Follow these step

按照这些步骤

  1. Install colordiff eg: for Ubuntu sudo apt-get install colordiff

  2. Now you can just try svn diff output to colordiff: svn diff -r Rev1:Rev2 file | colordiff

  3. Add following code into your bash profile (~/.bashrc or ~/.bash_profile) to easily access.

    svndiff() { svn diff "${@}" | colordiff }

  4. source bash profile.

    source ~/.basrcNow it's ready use... You can just see the svn diff in your terminal most effectively.

    eg: svndiff

  1. 安装 colordiff 例如:对于 Ubuntu sudo apt-get install colordiff

  2. 现在您可以尝试将 svn diff 输出到 colordiff: svn diff -r Rev1:Rev2 file | 颜色差异

  3. 将以下代码添加到您的 bash 配置文件(~/.bashrc 或 ~/.bash_profile)中以轻松访问。

    svndiff() { svn diff "${@}" | 颜色差异 }

  4. 源 bash 配置文件。

    source ~/.basrc现在可以使用了...您可以最有效地在终端中查看 svn diff。

    例如:svndiff

回答by Gerben Versluis

I like having the revision and file in the statusline when using vimdiff with svn so I use the following:

在将 vimdiff 与 svn 一起使用时,我喜欢在状态行中包含修订版和文件,因此我使用以下内容:

svnvimdiff.sh

svnvimdiff.sh

#!/bin/bash
/usr/bin/vim -R -d -f --nofork -n -c "let F1='${5//$'\t'/ }' | set statusline=%{F1} | let F2='${3//$'\t'/ }' | setlocal statusline=%{F2}"  

explanation:

解释:

  • -R = readonly (we can not edit those files)
  • -d = diff mode (side by side)
  • -f = foreground (let svn wait)
  • --nofork = also foreground (let svn wait)
  • -n = skip swapfiles (we do not need the swapfiles since they are already temporary)
  • -c = execute vim command
  • let F1='${5//$'\t'/ }' (name for all windows with tab replaced because it does not display correctly)
  • set statusline=%{F1} (set name as global statusline)
  • let F2='${3//$'\t'/ }' (name for first window with tab replaced because it does not display correctly)
  • setlocal statusline=%{F2} (set statusline for first window)
  • -R = 只读(我们不能编辑这些文件)
  • -d = 差异模式(并排)
  • -f = 前景(让 svn 等待)
  • --nofork = 也是前景(让 svn 等待)
  • -n = 跳过交换文件(我们不需要交换文件,因为它们已经是临时文件)
  • -c = 执行 vim 命令
  • let F1='${5//$'\t'/ }' (所有窗口的名称都替换了制表符,因为它不能正确显示)
  • set statusline=%{F1}(设置名称为全局状态行)
  • let F2='${3//$'\t'/ }' (第一个窗口的名称,因为它没有正确显示,所以标签被替换了)
  • setlocal statusline=%{F2}(为第一个窗口设置状态行)

Add/change diff-cmd in $HOME/.subversion/config

$HOME/.subversion/config 中添加/更改 diff-cmd

diff-cmd = /yourpath/svnvimdiff.sh

Or use it inline:

或者内联使用它:

svn diff --diff-cmd /yourpath/svnvimdiff <file>