Forked from alecthegeek/Generate_GitSHA1_forAfile.sh
Created
December 30, 2019 18:22
-
-
Save mick-d/c73bc6ade2a922e0cfe3192175b3b394 to your computer and use it in GitHub Desktop.
Calculate Git sha1 for a file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(echo -en "blob $(cat $file|wc -c)\00";cat $file)|sha1sum -b | cut -d " " -f 1 | |
or of course | |
git hash-object $file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use Digest::SHA1; | |
my @input = <>; | |
my $content = join("", @input); | |
my $git_blob = 'blob' . ' ' . length($content) . "\0" . $content; | |
my $sha1 = Digest::SHA1->new(); | |
$sha1->add($git_blob); | |
print $sha1->hexdigest(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment