Git search commit with specific unicode char in content

Viewed 73

I want to get all commits with a specific unicode char (https://www.compart.com/fr/unicode/U+200B) : Zero Width Space (U+200B).

git log -G 'regex'

This command should give me all commits with content that match the regex (Git Doc).

I want to catch Zero Width Space but the following command returns me an empty list :

git ls -G '\u200b'

But, I have some commits with this type of character. git diff gives me :

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

What's the way to search for unicode char in commits ?

1 Answers

I could only get it to work with the help of ANSI C quoting, i.e. $'\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
Related