Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How detect a Git SHA ID in a text

Tags:

git

commit

sha

A Git SHA ID looks like this one 351e11dac558a764ba83f89c6598151d2dbaf904, it is a long hex number. But how should it be detected in a text? Search for "words" which only contain 0-9,a-f and have a length of at least 20 characters? But how to distinguish SHA IDs from normal words?

like image 660
Mot Avatar asked Nov 15 '22 08:11

Mot


1 Answers

Yes, your approach will work. Remember, though, SHA1 is a general algorithm (not git specific), so it's possible your text could contain other SHA1 hashes in it which will also be 40 character hex strings.

like image 177
Jason Ardell Avatar answered Dec 09 '22 09:12

Jason Ardell