【问题标题】:In mercurial is there a way to tell hg log and diff to skip binary diffs?在 mercurial 中有没有办法告诉 hg log 和 diff 跳过二进制差异?
【发布时间】:2016-12-15 17:54:21
【问题描述】:

如果我使用hg log -phg diff 梳理差异,很高兴看到“二进制文件不同”之类的内容,而不必滚动屏幕上的乱码才能进入下一个文件。有没有配置技巧可以做到这一点?

(在预览中,如果没有设置简单的hg 选项,那么this question 中可能会有一些正确方向的提示。不过,我仍然需要更多帮助才能得到我想要的。)

【问题讨论】:

  • 您能否提供一个重现最小示例的步骤列表?目前尝试并没有看到这样的乱码,只有一行说明“二进制文件 some.blob 已更改”
  • 我想要你所拥有的!例如,当我有一个更改 pdf 的变更集时,hg log -prhg diff --change 给我的输出如下:GIT binary patch — literal 467997 — zc%0O_1#lcqvMxHZ(3UJ_mc6W7... (多行)
  • 有一个 -a / --text 选项可以强制文本输出,如果某些东西被意外检测为二进制,但似乎没有提供相反的内容。我刚刚了解到二进制检测是 based on the presense of NUL bytes in the file. 我的 pdf 中肯定有一些 NUL 字节字符串。

标签: mercurial diff binaryfiles


【解决方案1】:

在@arhak 的帮助下,我发现问题出在我的.hgrc

[diff]
git = True

我忘记了我在阅读this advice 之后补充说,git 样式的差异比 Mercurial 默认的补丁样式的差异更具可读性。我找不到对差异的描述,但现在看一些差异,--git (-g) 似乎在文件名标题中遗漏了日期,显然,它还强制使用完整的 uuencode 样式差异二进制文件。我想我会将它保留为默认值,但如果在我正在查看包含大量二进制文件更改的补丁的异常情况下将其关闭。

override at the commandline不编辑.hgrc,添加--config diff.git=False

我很好奇是否有一种方法可以跳过二进制文件,但在 diff 中保留常规文本文件的 git 格式。

【讨论】:

    【解决方案2】:

    这是我得到的,请检查 mercurial 版本,以防万一

    我在想也许你有一个扩展,可以用 blob 制作花哨的东西,因为我无法理解你的描述。我刚收到Binary file doc.pdf has changed

    $ hg version
    Mercurial Distributed SCM (version 3.9.2)
    ...
    $ mkdir hg-test
    $ cd hg-test
    $ hg init
    $ echo a text line > text.txt
    $ hg add text.txt
    $ hg commit -m "1st"
    $ echo another text line >> text.txt
    $ hg commit -m "2nd"
    $ hg add doc.pdf
    $ hg commit -m "a binary file"
    $ hg commit -m "modified the binary file"
    $ hg diff --change 3
    diff -r 2fd7730bc3bb -r 155aefdccfbe doc.pdf
    Binary file doc.pdf has changed
    $ hg diff --change 1
    diff -r 9e171966ad0d -r 105aa77984c0 text.txt
    --- a/text.txt  Sat Dec 17 12:18:46 2016 +0100
    +++ b/text.txt  Sat Dec 17 12:19:28 2016 +0100
    @@ -1,1 +1,2 @@
     a text line
    +another text line
    $ hg log -pr0:3
    changeset:   0:9e171966ad0d
    user:        arhak
    date:        Sat Dec 17 12:18:46 2016 +0100
    summary:     1st
    
    diff -r 000000000000 -r 9e171966ad0d text.txt
    --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
    +++ b/text.txt  Sat Dec 17 12:18:46 2016 +0100
    @@ -0,0 +1,1 @@
    +a text line
    
    changeset:   1:105aa77984c0
    user:        arhak
    date:        Sat Dec 17 12:19:28 2016 +0100
    summary:     2nd
    
    diff -r 9e171966ad0d -r 105aa77984c0 text.txt
    --- a/text.txt  Sat Dec 17 12:18:46 2016 +0100
    +++ b/text.txt  Sat Dec 17 12:19:28 2016 +0100
    @@ -1,1 +1,2 @@
     a text line
    +another text line
    
    changeset:   2:2fd7730bc3bb
    user:        arhak
    date:        Sat Dec 17 12:27:38 2016 +0100
    summary:     a binary file
    
    diff -r 105aa77984c0 -r 2fd7730bc3bb doc.pdf
    Binary file doc.pdf has changed
    
    changeset:   3:155aefdccfbe
    tag:         tip
    user:        arhak
    date:        Sat Dec 17 12:28:50 2016 +0100
    summary:     modified the binary file
    
    diff -r 2fd7730bc3bb -r 155aefdccfbe doc.pdf
    Binary file doc.pdf has changed
    

    【讨论】:

    • 谢谢!在我的 hg 版本中,我是你落后的一点——但更新没有帮助。不过,根据您的想法,我尝试了mv .hgrc .hgrc.bak,并且使用默认配置我确实得到“二进制文件...已更改”。在我缩小到罪魁祸首之后,我会尝试跟进。
    猜你喜欢
    • 2011-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多