<story><title>Generate a Git repository with 2^28 commits—one for every 7-character shorthash</title><url>https://github.com/not-an-aardvark/every-git-commit-shorthash</url></story><parent_chain></parent_chain><comment><author>anyfoo</author><text>While we&amp;#x27;re being silly, here&amp;#x27;s a shell oneliner that outputs its own SHA1 hash[1]:&lt;p&gt;A=shasum; C=echo; I=&amp;#x27;($C &amp;quot;A$s$A$X C$s$C$X I$s$Q$I$Q$X Q$s$k$Q$k$X k$s$Q$k$Q$X X$s$Q$X$Q$X s$s$Q$s$Q$X $I&amp;quot; | $A)&amp;#x27;; Q=&amp;quot;&amp;#x27;&amp;quot;; k=&amp;#x27;&amp;quot;&amp;#x27;; X=&amp;#x27;;&amp;#x27;; s=&amp;#x27;=&amp;#x27;; ($C &amp;quot;A$s$A$X C$s$C$X I$s$Q$I$Q$X Q$s$k$Q$k$X k$s$Q$k$Q$X X$s$Q$X$Q$X s$s$Q$s$Q$X $I&amp;quot; | $A)&lt;p&gt;Note that this is not in any way opening its own source code as a file or through shell magic or something like that, in fact it&amp;#x27;s not looking at its own code &lt;i&gt;at all&lt;/i&gt;. It really generates its own hash computationally out of itself, and would work the same if this was a compiled C program computing (not containing!) the hash of its own source code, even if the source code was thrown away.&lt;p&gt;This may seem impossible at first, but it&amp;#x27;s really just a funny variant of a quine (a program that prints its own source). &lt;a href=&quot;http:&amp;#x2F;&amp;#x2F;www.madore.org&amp;#x2F;~david&amp;#x2F;computers&amp;#x2F;quine.html&quot; rel=&quot;nofollow&quot;&gt;http:&amp;#x2F;&amp;#x2F;www.madore.org&amp;#x2F;~david&amp;#x2F;computers&amp;#x2F;quine.html&lt;/a&gt; came up with the idea and explains the concept.&lt;p&gt;[1] You could trivially change it to output its SHA2 hash instead (which just wasn&amp;#x27;t as common at the time I did this), but then you&amp;#x27;d loose the particularly &amp;quot;nice&amp;quot; hash. That property is entirely unrelated to outputting its own hash, and done the same as the commit hashes linked here.</text></comment>
<story><title>Generate a Git repository with 2^28 commits—one for every 7-character shorthash</title><url>https://github.com/not-an-aardvark/every-git-commit-shorthash</url></story><parent_chain></parent_chain><comment><author>sverhagen</author><text>As the README.md acknowledges, the usefulness may be limited, except for the fun in experimentation. What may not be obvious to basic Git users is that, while it may take 2^28 commits to fill up the entire address space of the 7-character shorthash, they are not designed to be unique (they are just the first part of the longer, unique hash). As a result, even relatively small repositories often already have _some_ duplicate shorthashes. And people scripting around their Git shorthashes must be prepared to deal with larger shorthashes, like 8-characters, 9, 10, 11, whatever it takes to disambiguate. My random Git repository of a mere 16865 commits (well, that&amp;#x27;s just &amp;quot;master&amp;quot;) that I&amp;#x27;m looking at over here, nothing out of the ordinary, needs shorthashes up to 11 characters to disambiguate all of them. (Not all the clashes may be on the same or main branch.)</text></comment>