【问题标题】:Git search commit with specific unicode char in content内容中包含特定 unicode char 的 Git 搜索提交
【发布时间】:2022-01-03 15:18:02
【问题描述】:

我想使用特定的 unicode char (https://www.compart.com/fr/unicode/U+200B) 获取所有提交:零宽度空间 (U+200B)。

git log -G 'regex'

这个命令应该给我所有内容与正则表达式匹配的提交 (Git Doc)。

我想捕捉零宽度空间,但以下命令返回一个空列表:

git ls -G '\u200b'

但是,我对这种类型的角色有一些提交。 git diff 给我:

-       path(r'v1/status<U+200B>/<str:key>', views.status, name="status<U+200B>"),

在提交中搜索 unicode char 的方法是什么?

【问题讨论】:

  • 试试\xE2\x80\x8B
  • 返回空结果
  • 您确定&lt;U+200B&gt; 没有保存为字符串吗? (对我来说,它似乎是模板引擎的一部分)
  • 是的,Git 用 git log -S "" 和 git log -G "" 返回一个空结果

标签: regex git unicode


【解决方案1】:

我只能在ANSI C quoting 的帮助下让它工作,即$'\u200b'

zb@db:/tmp$ mkdir so70109544
zb@db:/tmp$ cd so70109544/
zb@db:/tmp/so70109544$ git init
Initialized empty Git repository in /tmp/so70109544/.git/
zb@db:/tmp/so70109544$ perl -e 'print "\xe2\x80\x8b"' > test.txt
zb@db:/tmp/so70109544$ git add test.txt
zb@db:/tmp/so70109544$ git ci -m "test"
[master (root-commit) 4775358] test
 1 file changed, 1 insertion(+)
 create mode 100644 test.txt
zb@db:/tmp/so70109544$ git log -G $'\u200b'
commit 47753580a0e8e32af4e6c272d7ffdf0170f5bdd2 (HEAD -> master)
Author: zb <zb@somewhere.xyz>
Date:   Thu Nov 25 12:34:04 2021 +0100

    test

【讨论】:

    猜你喜欢
    • 2016-06-28
    • 2012-12-06
    • 2012-02-19
    • 2015-04-30
    • 1970-01-01
    • 2013-09-20
    • 1970-01-01
    • 2019-04-28
    相关资源
    最近更新 更多