git 中的 CVS 风格差异

发布于 2025-01-05 06:29:06 字数 113 浏览 0 评论 0原文

有没有办法让git diffs的输出格式像cvs风格的diffs一样?我发现 git diffs 的可读性较差。另外,more 中出现的 git diff 很烦人 - 我怎样才能禁用它?

Is there any way to make the output format of git diffs like cvs style diffs? I find git diffs to be less readable. Also, the git diffs appearing in more are annoying - how can I disable this?

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

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

发布评论

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

评论(3

过期情话 2025-01-12 06:29:06

默认情况下,git diff 使用“通用”格式 diff -ucvs diff 使用较旧的标准 diff 格式(已删除的行用 < 标记,添加的行用 > 标记,每个差异周围没有上下文) 。

例如,您可以使用 git diff -c 或 git diff -C5 获取“上下文差异”,以获取 5 行上下文,而不是默认的 3 行。

< code>diff --normal (至少如果你使用的是 GNU diffutils)会产生一个旧式的 diff,但是 git diff 似乎无法识别 - -正常选项。

就我个人而言,我发现上下文差异比旧式差异更具可读性,因此我从未发现需要将旧式差异与 git diff 一起使用。尝试 git diff -c (以及 haggai_e 禁用寻呼机的建议)。

如果您确实想要旧式差异(<>,无上下文),可能有一种方法可以做到。

编辑:

如果git diff不符合您的要求,您可以提取文件修订版本的副本,并使用您喜欢的任何差异工具。我自己的 get-versions 工具可以提取多个版本来自 git(或来自 RCS 或 CVS)的文件。

这是另一个解决方案,尽管它有点复杂。例如,我为 git 本身克隆了 git 存储库。如果我想比较顶级 README 文件的两个连续版本,我可以这样做:

$ diff --normal <(git show 779d7e93773a0dcf918dc77023511fdc68161bd8:README) \
                <(git show 71ce415dc088f19a0b8d6c8567dfdd6d851842b2:README)
24,26c24,25
< compatible with the GPLv2).
< It was originally written by Linus Torvalds with help of a group of
< hackers around the net. It is currently maintained by Junio C Hamano.
---
> compatible with the GPLv2). It was originally written by Linus
> Torvalds with help of a group of hackers around the net.
$ 

将其包装在一个小脚本中很容易。

请注意,: 后面的文件路径(上例中的 README)是相对于存储库的根目录,而不是相对于当前目录。您可以在名称前添加 ./ 使其相对于当前目录。 (后者可能不适用于某些旧版本的 git。)

git diff uses the "universal" format, diff -u, by default. cvs diff uses the older standard diff format (deleted lines marked with <, added lines marked with >, no context around each difference).

You can get a "context diff" using git diff -c, or git diff -C5, for example, to get 5 lines of context rather than the default 3.

diff --normal (at least if you're using GNU diffutils) will produce an old-style diff, but git diff doesn't seem to recognize the --normal option.

Personally, I find context diffs much more readable than old-style diffs, so I've never found the need to use old-style diffs with git diff. Try git diff -c (along with haggai_e's suggestion to disable the pager).

If you really want the old-style diffs (<, >, no context), there's probably a way to do it.

EDIT :

If git diff doesn't do what you want, you can extract copies of the revisions of the file and use whatever diff tool you like on them. My own get-versions tool can extract multiple versions of a file from git (or from RCS or CVS).

And here's another solution, though it's a bit more complicated. As an example, I've cloned the git repo for git itself. If I want to compare two successive versions of the top-level README file, I can do this:

$ diff --normal <(git show 779d7e93773a0dcf918dc77023511fdc68161bd8:README) \
                <(git show 71ce415dc088f19a0b8d6c8567dfdd6d851842b2:README)
24,26c24,25
< compatible with the GPLv2).
< It was originally written by Linus Torvalds with help of a group of
< hackers around the net. It is currently maintained by Junio C Hamano.
---
> compatible with the GPLv2). It was originally written by Linus
> Torvalds with help of a group of hackers around the net.
$ 

It would be easy enough to wrap this in a small script.

Note that the file path following the : (README in the above example) is relative to the root of the repository, not to the current directory. You can precede the name with ./ to make to make it relative to the current directory. (The latter might not work with some older versions of git.)

心舞飞扬 2025-01-12 06:29:06

您可以通过将 core.pager 设置为空字符串来禁用寻呼机:

git config --global core.pager ''

You can disable the pager by setting core.pager to an empty string:

git config --global core.pager ''
静水深流 2025-01-12 06:29:06

尝试使用标准 diff 格式:

git difftool -y -x "diff --unchanged-group-format='' --old-line-format='< %L' --new-line-format='> %L'"

这会提供类似 CVS 的换行符和旧行,没有上下文,但它不会在不同行组之间插入额外内容。不太确定如何实现其余部分,因为我不知道您想要 CVS 式格式的程度。

man diff

有关更多信息,

另请参阅

git difftool -y -x "diff -n"

但我怀疑这是否符合您的要求。如果这对您有用,要使其每次与 git diff 一起工作,请参阅 使用以下命令配置 diff 工具.gitconfig?,引用 http://jeetworks.com/node/90在接受的答案中。

Try playing with standard diff formatting:

git difftool -y -x "diff --unchanged-group-format='' --old-line-format='< %L' --new-line-format='> %L'"

This gives CVS-like newlines and oldlines, with no context, but it doesn't insert the extras between groups of different lines. Not quite sure how to achieve the rest, given I don't know the extent to which you would like CVS-like formatting.

man diff

For more information

Also see

git difftool -y -x "diff -n"

But I doubt this does what you want. If this does work for you, to make it work every time with git diff, see Configuring diff tool with .gitconfig?, which references http://jeetworks.com/node/90 in the accepted answer.

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