A Regex to match a SHA1

后端 未结 6 2002
旧巷少年郎
旧巷少年郎 2020-12-02 18:37

I\'m trying to match SHA1\'s in generic text with a regular expression.

Ideally I want to avoid matching words.

It\'s safe to say that full SHA1\'s have a d

6条回答
  •  臣服心动
    2020-12-02 19:09

    If you have access to the repo, you can use git cat-file -e to check for sure that it represents an object in the repo. This is very fast, too. If you further want to restrict this to just commits and tags, you can use git cat-file -t to find out the type of the object.

    This could be used, for example, to search human-generated text for mentions of git commits and generate hyperlinks to a git web interface.

提交回复
热议问题