<feed
    xmlns="http://www.w3.org/2005/Atom"
    xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xml:lang="en">
  <link rel="self"      type="application/atom+xml" href="https://euandre.org/en/til/feed.git.xml" />
  <link rel="alternate" type="text/html"            href="https://euandre.org/en/til/" hreflang="en" />
  <title>EuAndreh&apos;s website</title>
  <subtitle>TIL</subtitle>
  <id>https://euandre.org/en/til/feed.git.xml</id>
  <updated>2026-09-13T12:14:51+00:00</updated>
  <author>
    <name>EuAndreh</name>
    <email>eu@euandre.org</email>
  </author>
  <entry xml:lang="en">
    <title type="html">
      Storing CI data on Git notes
    </title>
    <link type="text/html" rel="alternative" href="https://euandre.org/en/til/2020/11/30/git-notes-ci.html" title="Storing CI data on Git notes" />
    <published>
      2020-11-30T00:00:00+00:00
    </published>
    <id>
      https://euandre.org/en/til/2020/11/30/git-notes-ci.html
    </id>
    <author>
      <name>
        EuAndreh
      </name>
      <email>
        eu@euandre.org
      </email>
    </author>
    <summary type="html">
        &lt;div class=&quot;paragraph&quot;&gt;
          &lt;p&gt;Extending the bare bones CI server I’ve &lt;a href=&quot;../12/diy-nix-bash-ci.html&quot;&gt;talked about before&lt;/a&gt;,
          divoplade on Freenode suggested storing CI artifacts on &lt;a href=&quot;https://git-scm.com/docs/git-notes&quot;&gt;Git
          notes&lt;/a&gt;, such as tarballs, binaries, logs, &lt;em&gt;etc&lt;/em&gt;.&lt;/p&gt;
        &lt;/div&gt;
    </summary>
    <content type="html" xml:base="en/til/2020/11/30/git-notes-ci.html">
        &lt;div class=&quot;paragraph&quot;&gt;
          &lt;p&gt;Extending the bare bones CI server I’ve &lt;a href=&quot;../12/diy-nix-bash-ci.html&quot;&gt;talked about before&lt;/a&gt;,
          divoplade on Freenode suggested storing CI artifacts on &lt;a href=&quot;https://git-scm.com/docs/git-notes&quot;&gt;Git
          notes&lt;/a&gt;, such as tarballs, binaries, logs, &lt;em&gt;etc&lt;/em&gt;.&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;paragraph&quot;&gt;
          &lt;p&gt;I’ve written a small script that will put log files and CI job data on Git notes, and make it visible on
          the porcelain log. It is a simple extension of the previous article:&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;listingblock&quot;&gt;
          &lt;div class=&quot;content&quot;&gt;
            &lt;table&gt;
              &lt;tbody&gt;
                &lt;tr&gt;
                  &lt;td&gt;
                    &lt;pre class=&quot;lineno&quot;&gt;&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L1&quot;
     href=&quot;#B1-L1&quot;&gt;1&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L2&quot;
     href=&quot;#B1-L2&quot;&gt;2&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L3&quot;
     href=&quot;#B1-L3&quot;&gt;3&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L4&quot;
     href=&quot;#B1-L4&quot;&gt;4&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L5&quot;
     href=&quot;#B1-L5&quot;&gt;5&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L6&quot;
     href=&quot;#B1-L6&quot;&gt;6&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L7&quot;
     href=&quot;#B1-L7&quot;&gt;7&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L8&quot;
     href=&quot;#B1-L8&quot;&gt;8&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L9&quot;
     href=&quot;#B1-L9&quot;&gt;9&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L10&quot;
     href=&quot;#B1-L10&quot;&gt;10&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L11&quot;
     href=&quot;#B1-L11&quot;&gt;11&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L12&quot;
     href=&quot;#B1-L12&quot;&gt;12&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L13&quot;
     href=&quot;#B1-L13&quot;&gt;13&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L14&quot;
     href=&quot;#B1-L14&quot;&gt;14&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L15&quot;
     href=&quot;#B1-L15&quot;&gt;15&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L16&quot;
     href=&quot;#B1-L16&quot;&gt;16&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L17&quot;
     href=&quot;#B1-L17&quot;&gt;17&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L18&quot;
     href=&quot;#B1-L18&quot;&gt;18&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L19&quot;
     href=&quot;#B1-L19&quot;&gt;19&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L20&quot;
     href=&quot;#B1-L20&quot;&gt;20&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L21&quot;
     href=&quot;#B1-L21&quot;&gt;21&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L22&quot;
     href=&quot;#B1-L22&quot;&gt;22&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L23&quot;
     href=&quot;#B1-L23&quot;&gt;23&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L24&quot;
     href=&quot;#B1-L24&quot;&gt;24&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L25&quot;
     href=&quot;#B1-L25&quot;&gt;25&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L26&quot;
     href=&quot;#B1-L26&quot;&gt;26&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L27&quot;
     href=&quot;#B1-L27&quot;&gt;27&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L28&quot;
     href=&quot;#B1-L28&quot;&gt;28&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L29&quot;
     href=&quot;#B1-L29&quot;&gt;29&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L30&quot;
     href=&quot;#B1-L30&quot;&gt;30&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L31&quot;
     href=&quot;#B1-L31&quot;&gt;31&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L32&quot;
     href=&quot;#B1-L32&quot;&gt;32&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L33&quot;
     href=&quot;#B1-L33&quot;&gt;33&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L34&quot;
     href=&quot;#B1-L34&quot;&gt;34&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L35&quot;
     href=&quot;#B1-L35&quot;&gt;35&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L36&quot;
     href=&quot;#B1-L36&quot;&gt;36&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L37&quot;
     href=&quot;#B1-L37&quot;&gt;37&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L38&quot;
     href=&quot;#B1-L38&quot;&gt;38&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L39&quot;
     href=&quot;#B1-L39&quot;&gt;39&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L40&quot;
     href=&quot;#B1-L40&quot;&gt;40&lt;/a&gt;&lt;/pre&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                    &lt;pre&gt;#!/usr/bin/env bash
set -Eeuo pipefail
set -x

PREFIX=&apos;/srv/ci/vps&apos;
mkdir -p &quot;$PREFIX&quot;
read -r _ SHA _ # oldrev newrev refname
FILENAME=&quot;$(date -Is)-$SHA.log&quot;
LOGFILE=&quot;$PREFIX/$FILENAME&quot;
exec &amp;amp;&amp;gt; &amp;gt;(tee -a &quot;$LOGFILE&quot;)

echo &quot;Starting CI job at: $(date -Is)&quot;

finish() {
  STATUS=&quot;$?&quot;
  printf &quot;\n\n&amp;gt;&amp;gt;&amp;gt; exit status was %s\n&quot; &quot;$STATUS&quot;
  echo &quot;Finishing CI job at: $(date -Is)&quot;
  popd
  NOTE=$(cat &amp;lt;&amp;lt;EOF
See CI logs with:
  git notes --ref=refs/notes/ci-logs show $SHA
  git notes --ref=refs/notes/ci-data show $SHA
EOF
)
  git notes --ref=refs/notes/ci-data add -f -m &quot;$STATUS $FILENAME&quot;
  git notes --ref=refs/notes/ci-logs add -f -F &quot;$LOGFILE&quot;
  git notes add -f -m &quot;$NOTE&quot;
  printf &quot;\n\n&amp;gt;&amp;gt;&amp;gt; CI logs added as Git note.&quot;
}
trap finish EXIT

unset GIT_DIR
CLONE=&quot;$(mktemp -d)&quot;
git clone . &quot;$CLONE&quot;
pushd &quot;$CLONE&quot;
git config --global user.email git@euandre.org
git config --global user.name &apos;EuAndreh CI&apos;

./container make check site
./container make publish&lt;/pre&gt;
                  &lt;/td&gt;
                &lt;/tr&gt;
              &lt;/tbody&gt;
            &lt;/table&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;paragraph plaintext&quot;&gt;
          &lt;p&gt;&lt;a href=&quot;git-notes-ci.html.0.txt&quot;&gt;plaintext&lt;/a&gt;&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;paragraph&quot;&gt;
          &lt;p&gt;The important part is in the &lt;code&gt;finish()&lt;/code&gt; function: - #25 stores the exit status and the
          generated filename separated by spaces; - #26 adds the log file in a note using the
          &lt;code&gt;refs/notes/ci-logs&lt;/code&gt; ref; - #27 it adds a note to the commit saying how to see the logs.&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;paragraph&quot;&gt;
          &lt;p&gt;A commit now has an attached note, and shows it whenever you look at it:&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;listingblock&quot;&gt;
          &lt;div class=&quot;content&quot;&gt;
            &lt;table&gt;
              &lt;tbody&gt;
                &lt;tr&gt;
                  &lt;td&gt;
                    &lt;pre class=&quot;lineno&quot;&gt;&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L1&quot;
     href=&quot;#B2-L1&quot;&gt;1&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L2&quot;
     href=&quot;#B2-L2&quot;&gt;2&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L3&quot;
     href=&quot;#B2-L3&quot;&gt;3&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L4&quot;
     href=&quot;#B2-L4&quot;&gt;4&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L5&quot;
     href=&quot;#B2-L5&quot;&gt;5&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L6&quot;
     href=&quot;#B2-L6&quot;&gt;6&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L7&quot;
     href=&quot;#B2-L7&quot;&gt;7&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L8&quot;
     href=&quot;#B2-L8&quot;&gt;8&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L9&quot;
     href=&quot;#B2-L9&quot;&gt;9&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L10&quot;
     href=&quot;#B2-L10&quot;&gt;10&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L11&quot;
     href=&quot;#B2-L11&quot;&gt;11&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L12&quot;
     href=&quot;#B2-L12&quot;&gt;12&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L13&quot;
     href=&quot;#B2-L13&quot;&gt;13&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L14&quot;
     href=&quot;#B2-L14&quot;&gt;14&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L15&quot;
     href=&quot;#B2-L15&quot;&gt;15&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L16&quot;
     href=&quot;#B2-L16&quot;&gt;16&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L17&quot;
     href=&quot;#B2-L17&quot;&gt;17&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L18&quot;
     href=&quot;#B2-L18&quot;&gt;18&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L19&quot;
     href=&quot;#B2-L19&quot;&gt;19&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L20&quot;
     href=&quot;#B2-L20&quot;&gt;20&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L21&quot;
     href=&quot;#B2-L21&quot;&gt;21&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L22&quot;
     href=&quot;#B2-L22&quot;&gt;22&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L23&quot;
     href=&quot;#B2-L23&quot;&gt;23&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L24&quot;
     href=&quot;#B2-L24&quot;&gt;24&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L25&quot;
     href=&quot;#B2-L25&quot;&gt;25&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L26&quot;
     href=&quot;#B2-L26&quot;&gt;26&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L27&quot;
     href=&quot;#B2-L27&quot;&gt;27&lt;/a&gt;&lt;/pre&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                    &lt;pre&gt;$ git show 87c57133abd8be5d7cc46afbf107f59b26066575
commit 87c57133abd8be5d7cc46afbf107f59b26066575
Author: EuAndreh &amp;lt;eu@euandre.org&amp;gt;
Date:   Wed Feb 24 21:58:28 2021 -0300

    vps/machines.scm: Change path to cronjob files

Notes:
    See CI logs with:
      git notes --ref=refs/notes/ci-logs show 87c57133abd8be5d7cc46afbf107f59b26066575
      git notes --ref=refs/notes/ci-data show 87c57133abd8be5d7cc46afbf107f59b26066575

diff --git a/servers/vps/machines.scm b/servers/vps/machines.scm
index d1830ca..a4ccde7 100644
--- a/servers/vps/machines.scm
+++ b/servers/vps/machines.scm
@@ -262,8 +262,8 @@ pki &quot; mail-domain &quot; key  \&quot;&quot; (tls-priv-for mail-domain) &quot;\&quot;&quot;))
             (service mcron-service-type
                      (mcron-configuration
                       (jobs
-                       (list #~(job &quot;30 1 * * 1&quot; &quot;guix gc -d&quot;)
-                             #~(job &quot;30 0 * * *&quot; &quot;/var/lib/euandreh/backup.sh&quot;)))))
+                       (list #~(job &quot;30 1 * * 1&quot; &quot;/opt/bin/gc.sh&quot;)
+                             #~(job &quot;30 0 * * *&quot; &quot;/opt/bin/backup.sh&quot;)))))
             (service dhcp-client-service-type)
             #;
             (service opensmtpd-service-type&lt;/pre&gt;
                  &lt;/td&gt;
                &lt;/tr&gt;
              &lt;/tbody&gt;
            &lt;/table&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;paragraph plaintext&quot;&gt;
          &lt;p&gt;&lt;a href=&quot;git-notes-ci.html.1.txt&quot;&gt;plaintext&lt;/a&gt;&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;paragraph&quot;&gt;
          &lt;p&gt;Other tools such as &lt;a href=&quot;https://git.zx2c4.com/cgit/&quot;&gt;cgit&lt;/a&gt; will also show notes on the web
          interface: &lt;a href=&quot;https://euandre.org/git/servers/commit?id=87c57133abd8be5d7cc46afbf107f59b26066575&quot;
             class=&quot;bare&quot;&gt;https://euandre.org/git/servers/commit?id=87c57133abd8be5d7cc46afbf107f59b26066575&lt;/a&gt;.&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;paragraph&quot;&gt;
          &lt;p&gt;You can go even further: since cgit can serve raw blob directly, you can even serve such artifacts (log
          files, release artifacts, binaries) from cgit itself:&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;listingblock&quot;&gt;
          &lt;div class=&quot;content&quot;&gt;
            &lt;table&gt;
              &lt;tbody&gt;
                &lt;tr&gt;
                  &lt;td&gt;
                    &lt;pre class=&quot;lineno&quot;&gt;&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B3-L1&quot;
     href=&quot;#B3-L1&quot;&gt;1&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B3-L2&quot;
     href=&quot;#B3-L2&quot;&gt;2&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B3-L3&quot;
     href=&quot;#B3-L3&quot;&gt;3&lt;/a&gt;&lt;/pre&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                    &lt;pre&gt;$ SHA=&quot;$(git notes --ref=refs/notes/ci-logs list 87c57133abd8be5d7cc46afbf107f59b26066575)&quot;
$ echo &quot;https://euandre.org/git/servers/blob?id=$SHA&quot;
https://euandre.org/git/servers/blob?id=1707a97bae24e3864fe7943f8dda6d01c294fb5c&lt;/pre&gt;
                  &lt;/td&gt;
                &lt;/tr&gt;
              &lt;/tbody&gt;
            &lt;/table&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;paragraph plaintext&quot;&gt;
          &lt;p&gt;&lt;a href=&quot;git-notes-ci.html.2.txt&quot;&gt;plaintext&lt;/a&gt;&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;paragraph&quot;&gt;
          &lt;p&gt;And like that you’ll have cgit serving the artifacts for you: &lt;a href=
          &quot;https://euandre.org/git/servers/blob?id=1707a97bae24e3864fe7943f8dda6d01c294fb5c&quot;
             class=&quot;bare&quot;&gt;https://euandre.org/git/servers/blob?id=1707a97bae24e3864fe7943f8dda6d01c294fb5c&lt;/a&gt;.&lt;/p&gt;
        &lt;/div&gt;
    </content>
  </entry>
  <entry xml:lang="en">
    <title type="html">
      Git bisect automation
    </title>
    <link type="text/html" rel="alternative" href="https://euandre.org/en/til/2020/11/12/git-bisect-automation.html" title="Git bisect automation" />
    <published>
      2020-11-12T00:00:00+00:00
    </published>
    <id>
      https://euandre.org/en/til/2020/11/12/git-bisect-automation.html
    </id>
    <author>
      <name>
        EuAndreh
      </name>
      <email>
        eu@euandre.org
      </email>
    </author>
    <summary type="html">
        &lt;div class=&quot;paragraph&quot;&gt;
          &lt;p&gt;It is good to have an standardized way to run builds and tests on the repository of a project, so that you
          can find when a bug was introduced by using &lt;code&gt;git bisect run&lt;/code&gt;.&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;paragraph&quot;&gt;
    </summary>
    <content type="html" xml:base="en/til/2020/11/12/git-bisect-automation.html">
        &lt;div class=&quot;paragraph&quot;&gt;
          &lt;p&gt;It is good to have an standardized way to run builds and tests on the repository of a project, so that you
          can find when a bug was introduced by using &lt;code&gt;git bisect run&lt;/code&gt;.&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;paragraph&quot;&gt;
          &lt;p&gt;I’ve already been in the situation when a bug was introduced and I didn’t know how it even was occurring,
          and running Git bisect over hundreds of commits to pinpoint the failing commit was very empowering:&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;listingblock&quot;&gt;
          &lt;div class=&quot;content&quot;&gt;
            &lt;table&gt;
              &lt;tbody&gt;
                &lt;tr&gt;
                  &lt;td&gt;
                    &lt;pre class=&quot;lineno&quot;&gt;&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L1&quot;
     href=&quot;#B1-L1&quot;&gt;1&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L2&quot;
     href=&quot;#B1-L2&quot;&gt;2&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L3&quot;
     href=&quot;#B1-L3&quot;&gt;3&lt;/a&gt;&lt;/pre&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                    &lt;pre&gt;$ GOOD_COMMIT_SHA=e1fd0a817d192c5a5df72dd7422e36558fa78e46
$ git bisect start HEAD $GOOD_COMMIT_SHA
$ git bisect run sn -c &apos;./build.sh &amp;amp;&amp; ./run-failing-case.sh&apos;&lt;/pre&gt;
                  &lt;/td&gt;
                &lt;/tr&gt;
              &lt;/tbody&gt;
            &lt;/table&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;paragraph plaintext&quot;&gt;
          &lt;p&gt;&lt;a href=&quot;git-bisect-automation.html.0.txt&quot;&gt;plaintext&lt;/a&gt;&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;paragraph&quot;&gt;
          &lt;p&gt;Git will than do a binary search between the commits, and run the commands you provide it with to find the
          failing commit.&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;paragraph&quot;&gt;
          &lt;p&gt;Instead of being afraid of doing a bisect, you should instead leverage it, and make Git help you dig
          through the history of the repository to find the bad code.&lt;/p&gt;
        &lt;/div&gt;
    </content>
  </entry>
  <entry xml:lang="en">
    <title type="html">
      Search changes to a filename pattern in Git history
    </title>
    <link type="text/html" rel="alternative" href="https://euandre.org/en/til/2020/10/11/search-git-history.html" title="Search changes to a filename pattern in Git history" />
    <published>
      2020-10-11T00:00:00+00:00
    </published>
    <id>
      https://euandre.org/en/til/2020/10/11/search-git-history.html
    </id>
    <author>
      <name>
        EuAndreh
      </name>
      <email>
        eu@euandre.org
      </email>
    </author>
    <summary type="html">
        &lt;div class=&quot;paragraph&quot;&gt;
          &lt;p&gt;This is &lt;a href=&quot;../../08/14/browse-git.html&quot;&gt;yet&lt;/a&gt; &lt;a href=&quot;../../08/16/git-search.html&quot;&gt;another&lt;/a&gt;
          &lt;a href=&quot;../../08/28/grep-online.html&quot;&gt;&quot;search in Git&quot;&lt;/a&gt; TIL entry. You could say that Git has a
          unintuitive CLI, or that is it very powerful.&lt;/p&gt;
        &lt;/div&gt;
    </summary>
    <content type="html" xml:base="en/til/2020/10/11/search-git-history.html">
        &lt;div class=&quot;paragraph&quot;&gt;
          &lt;p&gt;This is &lt;a href=&quot;../../08/14/browse-git.html&quot;&gt;yet&lt;/a&gt; &lt;a href=&quot;../../08/16/git-search.html&quot;&gt;another&lt;/a&gt;
          &lt;a href=&quot;../../08/28/grep-online.html&quot;&gt;&quot;search in Git&quot;&lt;/a&gt; TIL entry. You could say that Git has a
          unintuitive CLI, or that is it very powerful.&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;paragraph&quot;&gt;
          &lt;p&gt;I wanted to search for an old file that I new that was in the history of the repository, but was deleted
          some time ago. So I didn’t really remember the name, only bits of it.&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;paragraph&quot;&gt;
          &lt;p&gt;I immediately went to the list of TILs I had written on searching in Git, but it wasn’t readily obvious
          how to do it, so here it goes:&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;listingblock&quot;&gt;
          &lt;div class=&quot;content&quot;&gt;
            &lt;table&gt;
              &lt;tbody&gt;
                &lt;tr&gt;
                  &lt;td&gt;
                    &lt;pre class=&quot;lineno&quot;&gt;&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L1&quot;
     href=&quot;#B1-L1&quot;&gt;1&lt;/a&gt;&lt;/pre&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                    &lt;pre&gt;git log -- *pattern*&lt;/pre&gt;
                  &lt;/td&gt;
                &lt;/tr&gt;
              &lt;/tbody&gt;
            &lt;/table&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;paragraph plaintext&quot;&gt;
          &lt;p&gt;&lt;a href=&quot;search-git-history.html.0.txt&quot;&gt;plaintext&lt;/a&gt;&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;paragraph&quot;&gt;
          &lt;p&gt;You could add globs before the pattern to match things on any directory, and add our &lt;code&gt;-p&lt;/code&gt;
          friend to promptly see the diffs:&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;listingblock&quot;&gt;
          &lt;div class=&quot;content&quot;&gt;
            &lt;table&gt;
              &lt;tbody&gt;
                &lt;tr&gt;
                  &lt;td&gt;
                    &lt;pre class=&quot;lineno&quot;&gt;&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L1&quot;
     href=&quot;#B2-L1&quot;&gt;1&lt;/a&gt;&lt;/pre&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                    &lt;pre&gt;git log -p -- **/*pattern*&lt;/pre&gt;
                  &lt;/td&gt;
                &lt;/tr&gt;
              &lt;/tbody&gt;
            &lt;/table&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;paragraph plaintext&quot;&gt;
          &lt;p&gt;&lt;a href=&quot;search-git-history.html.1.txt&quot;&gt;plaintext&lt;/a&gt;&lt;/p&gt;
        &lt;/div&gt;
    </content>
  </entry>
  <entry xml:lang="en">
    <title type="html">
      Pull requests with Git, the old school way
    </title>
    <link type="text/html" rel="alternative" href="https://euandre.org/en/til/2020/09/05/oldschool-pr.html" title="Pull requests with Git, the old school way" />
    <published>
      2020-09-05T00:00:00+00:00
    </published>
    <id>
      https://euandre.org/en/til/2020/09/05/oldschool-pr.html
    </id>
    <author>
      <name>
        EuAndreh
      </name>
      <email>
        eu@euandre.org
      </email>
    </author>
    <summary type="html">
        &lt;div id=&quot;preamble&quot;&gt;
          &lt;div class=&quot;sectionbody&quot;&gt;
            &lt;div class=&quot;paragraph&quot;&gt;
              &lt;p&gt;It might be news to you, as it was to me, that &quot;pull requests&quot; that you can create on a Git hosting
              provider’s web UIfootnote:pr-webui[ And maybe even using the Git hosting provider’s API from the command
    </summary>
    <content type="html" xml:base="en/til/2020/09/05/oldschool-pr.html">
        &lt;div id=&quot;preamble&quot;&gt;
          &lt;div class=&quot;sectionbody&quot;&gt;
            &lt;div class=&quot;paragraph&quot;&gt;
              &lt;p&gt;It might be news to you, as it was to me, that &quot;pull requests&quot; that you can create on a Git hosting
              provider’s web UIfootnote:pr-webui[ And maybe even using the Git hosting provider’s API from the command
              line! ] like GitLab/Bitbucket/GitHub actually comes from Git itself: &lt;code&gt;git request-pull&lt;/code&gt;.&lt;/p&gt;
            &lt;/div&gt;
            &lt;div class=&quot;paragraph&quot;&gt;
              &lt;p&gt;At the very core, they accomplish the same thing: both the original and the web UI ones are ways for
              you to request the project maintainers to pull in your changes from your fork. It’s like saying: &quot;hi
              there, I did some changes on my clone of the repository, what do you think about bringing those in?&quot;.&lt;/p&gt;
            &lt;/div&gt;
            &lt;div class=&quot;paragraph&quot;&gt;
              &lt;p&gt;The only difference is that you’re working with only Git itself, so you’re not tied to any Git hosting
              provider: you can send pull requests across them transparently! You could even use your own &lt;a href=
              &quot;https://git.zx2c4.com/cgit/&quot;&gt;cgit&lt;/a&gt; installation. No need to be locked in by any of them, putting the
              &quot;D&quot; back in &quot;DVCS&quot;: it’s a &lt;strong&gt;distributed&lt;/strong&gt; version control system.&lt;/p&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;sect1&quot;&gt;
          &lt;h2 id=&quot;git-request-pull-introduction&quot;&gt;&lt;code&gt;git request-pull&lt;/code&gt; introduction&lt;a class=&quot;anchor&quot;
             href=&quot;#git-request-pull-introduction&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
          &lt;div class=&quot;sectionbody&quot;&gt;
            &lt;div class=&quot;paragraph&quot;&gt;
              &lt;p&gt;Here’s the raw output of a &lt;code&gt;git request-pull&lt;/code&gt;:&lt;/p&gt;
            &lt;/div&gt;
            &lt;div class=&quot;listingblock&quot;&gt;
              &lt;div class=&quot;content&quot;&gt;
                &lt;table&gt;
                  &lt;tbody&gt;
                    &lt;tr&gt;
                      &lt;td&gt;
                        &lt;pre class=&quot;lineno&quot;&gt;&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L1&quot;
     href=&quot;#B1-L1&quot;&gt;1&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L2&quot;
     href=&quot;#B1-L2&quot;&gt;2&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L3&quot;
     href=&quot;#B1-L3&quot;&gt;3&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L4&quot;
     href=&quot;#B1-L4&quot;&gt;4&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L5&quot;
     href=&quot;#B1-L5&quot;&gt;5&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L6&quot;
     href=&quot;#B1-L6&quot;&gt;6&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L7&quot;
     href=&quot;#B1-L7&quot;&gt;7&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L8&quot;
     href=&quot;#B1-L8&quot;&gt;8&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L9&quot;
     href=&quot;#B1-L9&quot;&gt;9&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L10&quot;
     href=&quot;#B1-L10&quot;&gt;10&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L11&quot;
     href=&quot;#B1-L11&quot;&gt;11&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L12&quot;
     href=&quot;#B1-L12&quot;&gt;12&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L13&quot;
     href=&quot;#B1-L13&quot;&gt;13&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L14&quot;
     href=&quot;#B1-L14&quot;&gt;14&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L15&quot;
     href=&quot;#B1-L15&quot;&gt;15&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L16&quot;
     href=&quot;#B1-L16&quot;&gt;16&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L17&quot;
     href=&quot;#B1-L17&quot;&gt;17&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L18&quot;
     href=&quot;#B1-L18&quot;&gt;18&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L19&quot;
     href=&quot;#B1-L19&quot;&gt;19&lt;/a&gt;&lt;/pre&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                        &lt;pre&gt;$ git request-pull HEAD public-origin
The following changes since commit 302c9f2f035c0360acd4e13142428c100a10d43f:

  db post: Add link to email exchange (2020-09-03 21:23:55 -0300)

are available in the Git repository at:

  https://euandre.org/git/euandre.org/

for you to fetch changes up to 524c646cdac4153e54f2163e280176adbc4873fa:

  db post: better pinpoint sqlite unsuitability (2020-09-03 22:08:56 -0300)

----------------------------------------------------------------
EuAndreh (1):
      db post: better pinpoint sqlite unsuitability

 _posts/2020-08-31-the-database-i-wish-i-had.md | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)&lt;/pre&gt;
                      &lt;/td&gt;
                    &lt;/tr&gt;
                  &lt;/tbody&gt;
                &lt;/table&gt;
              &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class=&quot;paragraph plaintext&quot;&gt;
              &lt;p&gt;&lt;a href=&quot;oldschool-pr.html.0.txt&quot;&gt;plaintext&lt;/a&gt;&lt;/p&gt;
            &lt;/div&gt;
            &lt;div class=&quot;paragraph&quot;&gt;
              &lt;p&gt;That very first line is saying: &quot;create me a pull request with only a single commit, defined by
              &lt;code&gt;HEAD&lt;/code&gt;, and use the URL defined by &lt;code&gt;public-origin&lt;/code&gt;&quot;.&lt;/p&gt;
            &lt;/div&gt;
            &lt;div class=&quot;paragraph&quot;&gt;
              &lt;p&gt;Here’s a pitfall: you may try using your &lt;code&gt;origin&lt;/code&gt; remote at first where I put
              &lt;code&gt;public-origin&lt;/code&gt;, but that is many times pointing to something like
              &lt;code&gt;git@example.com&lt;/code&gt;, or &lt;code&gt;git.example.com:repo.git&lt;/code&gt; (check that with &lt;code&gt;git remote
              -v | grep origin&lt;/code&gt;). On both cases those are addresses available for interaction via SSH, and it
              would be better if your pull requests used an address ready for public consumption.&lt;/p&gt;
            &lt;/div&gt;
            &lt;div class=&quot;paragraph&quot;&gt;
              &lt;p&gt;A simple solution for that is for you to add the &lt;code&gt;public-origin&lt;/code&gt; alias as the HTTPS
              alternative to the SSH version:&lt;/p&gt;
            &lt;/div&gt;
            &lt;div class=&quot;listingblock&quot;&gt;
              &lt;div class=&quot;content&quot;&gt;
                &lt;table&gt;
                  &lt;tbody&gt;
                    &lt;tr&gt;
                      &lt;td&gt;
                        &lt;pre class=&quot;lineno&quot;&gt;&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L1&quot;
     href=&quot;#B2-L1&quot;&gt;1&lt;/a&gt;&lt;/pre&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                        &lt;pre&gt;$ git remote add public-origin https://example.com/user/repo&lt;/pre&gt;
                      &lt;/td&gt;
                    &lt;/tr&gt;
                  &lt;/tbody&gt;
                &lt;/table&gt;
              &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class=&quot;paragraph plaintext&quot;&gt;
              &lt;p&gt;&lt;a href=&quot;oldschool-pr.html.1.txt&quot;&gt;plaintext&lt;/a&gt;&lt;/p&gt;
            &lt;/div&gt;
            &lt;div class=&quot;paragraph&quot;&gt;
              &lt;p&gt;Every Git hosting provider exposes repositories via HTTPS.&lt;/p&gt;
            &lt;/div&gt;
            &lt;div class=&quot;paragraph&quot;&gt;
              &lt;p&gt;Experiment it yourself, and get acquainted with the CLI.&lt;/p&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;sect1&quot;&gt;
          &lt;h2 id=&quot;delivering-decentralized-pull-requests&quot;&gt;Delivering decentralized pull requests&lt;a class=&quot;anchor&quot;
             href=&quot;#delivering-decentralized-pull-requests&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
          &lt;div class=&quot;sectionbody&quot;&gt;
            &lt;div class=&quot;paragraph&quot;&gt;
              &lt;p&gt;Now that you can create the content of a pull request, you can just &lt;a href=
              &quot;../04/cli-email-fun-profit.html&quot;&gt;deliver it&lt;/a&gt; to the interested parties email:&lt;/p&gt;
            &lt;/div&gt;
            &lt;div class=&quot;listingblock&quot;&gt;
              &lt;div class=&quot;content&quot;&gt;
                &lt;table&gt;
                  &lt;tbody&gt;
                    &lt;tr&gt;
                      &lt;td&gt;
                        &lt;pre class=&quot;lineno&quot;&gt;&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B3-L1&quot;
     href=&quot;#B3-L1&quot;&gt;1&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B3-L2&quot;
     href=&quot;#B3-L2&quot;&gt;2&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B3-L3&quot;
     href=&quot;#B3-L3&quot;&gt;3&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B3-L4&quot;
     href=&quot;#B3-L4&quot;&gt;4&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B3-L5&quot;
     href=&quot;#B3-L5&quot;&gt;5&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B3-L6&quot;
     href=&quot;#B3-L6&quot;&gt;6&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B3-L7&quot;
     href=&quot;#B3-L7&quot;&gt;7&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B3-L8&quot;
     href=&quot;#B3-L8&quot;&gt;8&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B3-L9&quot;
     href=&quot;#B3-L9&quot;&gt;9&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B3-L10&quot;
     href=&quot;#B3-L10&quot;&gt;10&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B3-L11&quot;
     href=&quot;#B3-L11&quot;&gt;11&lt;/a&gt;&lt;/pre&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                        &lt;pre&gt;# send a PR with your last commit to the author&apos;s email
git request-pull HEAD public-origin | mail author@example.com -s &quot;PR: Add thing to repo&quot;

# send a PR with your last 5 commits to the project&apos;s mailing
# list, including the patch
git request-pull -p HEAD~5 public-origin | \
  mail list@example.com -s &quot;PR: Add another thing to repo&quot;

# send every commit that is new in &quot;other-branch&quot;
git request-pull master public-origin other-branch | \
  mail list@example.com -s &apos;PR: All commits from my &quot;other-brach&quot;&apos;&lt;/pre&gt;
                      &lt;/td&gt;
                    &lt;/tr&gt;
                  &lt;/tbody&gt;
                &lt;/table&gt;
              &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class=&quot;paragraph plaintext&quot;&gt;
              &lt;p&gt;&lt;a href=&quot;oldschool-pr.html.2.txt&quot;&gt;plaintext&lt;/a&gt;&lt;/p&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;sect1&quot;&gt;
          &lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;a class=&quot;anchor&quot;
             href=&quot;#conclusion&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
          &lt;div class=&quot;sectionbody&quot;&gt;
            &lt;div class=&quot;paragraph&quot;&gt;
              &lt;p&gt;In practice, I’ve never used or seen anyone use pull requests this way: everybody is just &lt;a href=
              &quot;https://drewdevault.com/2018/07/23/Git-is-already-distributed.html&quot;&gt;sending patches via email&lt;/a&gt;.&lt;/p&gt;
            &lt;/div&gt;
            &lt;div class=&quot;paragraph&quot;&gt;
              &lt;p&gt;If you stop to think about this model, the problem of &quot;Git hosting providers becoming too centralized&quot;
              is a non-issue, and &quot;Git federation&quot; proposals are a less attractive as they may sound initially.&lt;/p&gt;
            &lt;/div&gt;
            &lt;div class=&quot;paragraph&quot;&gt;
              &lt;p&gt;Using Git this way is not scary or so weird as the first impression may suggest. It is actually how
              Git was designed to be used.&lt;/p&gt;
            &lt;/div&gt;
            &lt;div class=&quot;paragraph&quot;&gt;
              &lt;p&gt;Check &lt;code&gt;git help request-pull&lt;/code&gt; for more info.&lt;/p&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
    </content>
  </entry>
  <entry xml:lang="en">
    <title type="html">
      Grep online repositories
    </title>
    <link type="text/html" rel="alternative" href="https://euandre.org/en/til/2020/08/28/grep-online.html" title="Grep online repositories" />
    <published>
      2020-08-28T00:00:00+00:00
    </published>
    <id>
      https://euandre.org/en/til/2020/08/28/grep-online.html
    </id>
    <author>
      <name>
        EuAndreh
      </name>
      <email>
        eu@euandre.org
      </email>
    </author>
    <summary type="html">
        &lt;div class=&quot;paragraph&quot;&gt;
          &lt;p&gt;I often find interesting source code repositories online that I want to grep for some pattern but I can’t,
          because either:&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;ulist&quot;&gt;
    </summary>
    <content type="html" xml:base="en/til/2020/08/28/grep-online.html">
        &lt;div class=&quot;paragraph&quot;&gt;
          &lt;p&gt;I often find interesting source code repositories online that I want to grep for some pattern but I can’t,
          because either:&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;ulist&quot;&gt;
          &lt;ul&gt;
            &lt;li&gt;
              &lt;p&gt;the repository is on &lt;a href=&quot;https://git.zx2c4.com/cgit/&quot;&gt;cgit&lt;/a&gt; or a similar code repository that
              doesn’t allow search in files, or;&lt;/p&gt;
            &lt;/li&gt;
            &lt;li&gt;
              &lt;p&gt;the search function is really bad, and doesn’t allow me to use regular expressions for searching
              patterns in the code.&lt;/p&gt;
            &lt;/li&gt;
          &lt;/ul&gt;
        &lt;/div&gt;
        &lt;div class=&quot;paragraph&quot;&gt;
          &lt;p&gt;Here’s a simple script that allows you to overcome that problem easily:&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;listingblock&quot;&gt;
          &lt;div class=&quot;content&quot;&gt;
            &lt;table&gt;
              &lt;tbody&gt;
                &lt;tr&gt;
                  &lt;td&gt;
                    &lt;pre class=&quot;lineno&quot;&gt;&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L1&quot;
     href=&quot;#B1-L1&quot;&gt;1&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L2&quot;
     href=&quot;#B1-L2&quot;&gt;2&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L3&quot;
     href=&quot;#B1-L3&quot;&gt;3&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L4&quot;
     href=&quot;#B1-L4&quot;&gt;4&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L5&quot;
     href=&quot;#B1-L5&quot;&gt;5&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L6&quot;
     href=&quot;#B1-L6&quot;&gt;6&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L7&quot;
     href=&quot;#B1-L7&quot;&gt;7&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L8&quot;
     href=&quot;#B1-L8&quot;&gt;8&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L9&quot;
     href=&quot;#B1-L9&quot;&gt;9&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L10&quot;
     href=&quot;#B1-L10&quot;&gt;10&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L11&quot;
     href=&quot;#B1-L11&quot;&gt;11&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L12&quot;
     href=&quot;#B1-L12&quot;&gt;12&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L13&quot;
     href=&quot;#B1-L13&quot;&gt;13&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L14&quot;
     href=&quot;#B1-L14&quot;&gt;14&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L15&quot;
     href=&quot;#B1-L15&quot;&gt;15&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L16&quot;
     href=&quot;#B1-L16&quot;&gt;16&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L17&quot;
     href=&quot;#B1-L17&quot;&gt;17&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L18&quot;
     href=&quot;#B1-L18&quot;&gt;18&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L19&quot;
     href=&quot;#B1-L19&quot;&gt;19&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L20&quot;
     href=&quot;#B1-L20&quot;&gt;20&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L21&quot;
     href=&quot;#B1-L21&quot;&gt;21&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L22&quot;
     href=&quot;#B1-L22&quot;&gt;22&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L23&quot;
     href=&quot;#B1-L23&quot;&gt;23&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L24&quot;
     href=&quot;#B1-L24&quot;&gt;24&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L25&quot;
     href=&quot;#B1-L25&quot;&gt;25&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L26&quot;
     href=&quot;#B1-L26&quot;&gt;26&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L27&quot;
     href=&quot;#B1-L27&quot;&gt;27&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L28&quot;
     href=&quot;#B1-L28&quot;&gt;28&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L29&quot;
     href=&quot;#B1-L29&quot;&gt;29&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L30&quot;
     href=&quot;#B1-L30&quot;&gt;30&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L31&quot;
     href=&quot;#B1-L31&quot;&gt;31&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L32&quot;
     href=&quot;#B1-L32&quot;&gt;32&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L33&quot;
     href=&quot;#B1-L33&quot;&gt;33&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L34&quot;
     href=&quot;#B1-L34&quot;&gt;34&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L35&quot;
     href=&quot;#B1-L35&quot;&gt;35&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L36&quot;
     href=&quot;#B1-L36&quot;&gt;36&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L37&quot;
     href=&quot;#B1-L37&quot;&gt;37&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L38&quot;
     href=&quot;#B1-L38&quot;&gt;38&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L39&quot;
     href=&quot;#B1-L39&quot;&gt;39&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L40&quot;
     href=&quot;#B1-L40&quot;&gt;40&lt;/a&gt;&lt;/pre&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                    &lt;pre&gt;#!/usr/bin/env bash
set -eu

end=&quot;\033[0m&quot;
red=&quot;\033[0;31m&quot;
red() { echo -e &quot;${red}${1}${end}&quot;; }

usage() {
  red &quot;Missing argument $1.\n&quot;
  cat &amp;lt;&amp;lt;EOF
Usage:
    $0 &amp;lt;REGEX_PATTERN&amp;gt; &amp;lt;REPOSITORY_URL&amp;gt;

      Arguments:
        REGEX_PATTERN     Regular expression that &quot;git grep&quot; can search
        REPOSITORY_URL    URL address that &quot;git clone&quot; can download the repository from

Examples:
    Searching &quot;make get-git&quot; in cgit repository:
        git search &apos;make get-git&apos; https://git.zx2c4.com/cgit/
        git search &apos;make get-git&apos; https://git.zx2c4.com/cgit/ -- \$(git rev-list --all)
EOF
  exit 2
}


REGEX_PATTERN=&quot;${1:-}&quot;
REPOSITORY_URL=&quot;${2:-}&quot;
[[ -z &quot;${REGEX_PATTERN}&quot; ]] &amp;amp;&amp; usage &apos;REGEX_PATTERN&apos;
[[ -z &quot;${REPOSITORY_URL}&quot; ]] &amp;amp;&amp; usage &apos;REPOSITORY_URL&apos;

mkdir -p /tmp/git-search
DIRNAME=&quot;$(echo &quot;${REPOSITORY_URL%/}&quot; | rev | cut -d/ -f1 | rev)&quot;
if [[ ! -d &quot;/tmp/git-search/${DIRNAME}&quot; ]]; then
  git clone &quot;${REPOSITORY_URL}&quot; &quot;/tmp/git-search/${DIRNAME}&quot;
fi
pushd &quot;/tmp/git-search/${DIRNAME}&quot;

shift 3 || shift 2 # when &quot;--&quot; is missing
git grep &quot;${REGEX_PATTERN}&quot; &quot;${@}&quot;&lt;/pre&gt;
                  &lt;/td&gt;
                &lt;/tr&gt;
              &lt;/tbody&gt;
            &lt;/table&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;paragraph plaintext&quot;&gt;
          &lt;p&gt;&lt;a href=&quot;grep-online.html.0.txt&quot;&gt;plaintext&lt;/a&gt;&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;paragraph&quot;&gt;
          &lt;p&gt;It is a wrapper around &lt;code&gt;git grep&lt;/code&gt; that downloads the repository when missing. Save in a file
          called &lt;code&gt;git-search&lt;/code&gt;, make the file executable and add it to your path.&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;paragraph&quot;&gt;
          &lt;p&gt;Overview:&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;ulist&quot;&gt;
          &lt;ul&gt;
            &lt;li&gt;
              &lt;p&gt;&lt;em&gt;lines 1~2&lt;/em&gt;:&lt;/p&gt;
              &lt;div class=&quot;paragraph&quot;&gt;
                &lt;p&gt;Bash shebang and the &lt;code&gt;set -eu&lt;/code&gt; options to exit on error or undefined variables.&lt;/p&gt;
              &lt;/div&gt;
            &lt;/li&gt;
            &lt;li&gt;
              &lt;p&gt;&lt;em&gt;lines 4~30&lt;/em&gt;:&lt;/p&gt;
              &lt;div class=&quot;paragraph&quot;&gt;
                &lt;p&gt;Usage text to be printed when providing less arguments than expected.&lt;/p&gt;
              &lt;/div&gt;
            &lt;/li&gt;
            &lt;li&gt;
              &lt;p&gt;&lt;em&gt;line 33&lt;/em&gt;:&lt;/p&gt;
              &lt;div class=&quot;paragraph&quot;&gt;
                &lt;p&gt;Extract the repository name from the URL, removing trailing slashes.&lt;/p&gt;
              &lt;/div&gt;
            &lt;/li&gt;
            &lt;li&gt;
              &lt;p&gt;&lt;em&gt;lines 34~37&lt;/em&gt;:&lt;/p&gt;
              &lt;div class=&quot;paragraph&quot;&gt;
                &lt;p&gt;Download the repository when missing and go to the folder.&lt;/p&gt;
              &lt;/div&gt;
            &lt;/li&gt;
            &lt;li&gt;
              &lt;p&gt;&lt;em&gt;line 39&lt;/em&gt;:&lt;/p&gt;
              &lt;div class=&quot;paragraph&quot;&gt;
                &lt;p&gt;Make the variable &lt;code&gt;$@&lt;/code&gt; contain the rest of the unused arguments.&lt;/p&gt;
              &lt;/div&gt;
            &lt;/li&gt;
            &lt;li&gt;
              &lt;p&gt;&lt;em&gt;line 40&lt;/em&gt;:&lt;/p&gt;
              &lt;div class=&quot;paragraph&quot;&gt;
                &lt;p&gt;Perform &lt;code&gt;git grep&lt;/code&gt;, forwarding the remaining arguments from &lt;code&gt;$@&lt;/code&gt;.&lt;/p&gt;
              &lt;/div&gt;
            &lt;/li&gt;
          &lt;/ul&gt;
        &lt;/div&gt;
        &lt;div class=&quot;paragraph&quot;&gt;
          &lt;p&gt;Example output:&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;listingblock&quot;&gt;
          &lt;div class=&quot;content&quot;&gt;
            &lt;table&gt;
              &lt;tbody&gt;
                &lt;tr&gt;
                  &lt;td&gt;
                    &lt;pre class=&quot;lineno&quot;&gt;&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L1&quot;
     href=&quot;#B2-L1&quot;&gt;1&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L2&quot;
     href=&quot;#B2-L2&quot;&gt;2&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L3&quot;
     href=&quot;#B2-L3&quot;&gt;3&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L4&quot;
     href=&quot;#B2-L4&quot;&gt;4&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L5&quot;
     href=&quot;#B2-L5&quot;&gt;5&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L6&quot;
     href=&quot;#B2-L6&quot;&gt;6&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L7&quot;
     href=&quot;#B2-L7&quot;&gt;7&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L8&quot;
     href=&quot;#B2-L8&quot;&gt;8&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L9&quot;
     href=&quot;#B2-L9&quot;&gt;9&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L10&quot;
     href=&quot;#B2-L10&quot;&gt;10&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L11&quot;
     href=&quot;#B2-L11&quot;&gt;11&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L12&quot;
     href=&quot;#B2-L12&quot;&gt;12&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L13&quot;
     href=&quot;#B2-L13&quot;&gt;13&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L14&quot;
     href=&quot;#B2-L14&quot;&gt;14&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L15&quot;
     href=&quot;#B2-L15&quot;&gt;15&lt;/a&gt;&lt;/pre&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                    &lt;pre&gt;$ git search &apos;make get-git&apos; https://git.zx2c4.com/cgit/
Clonage dans &apos;/tmp/git-search/cgit&apos;...
remote: Enumerating objects: 542, done.
remote: Counting objects: 100% (542/542), done.
remote: Compressing objects: 100% (101/101), done.
warning: object 51dd1eff1edc663674df9ab85d2786a40f7ae3a5: gitmodulesParse: could not parse gitmodules blob
remote: Total 7063 (delta 496), reused 446 (delta 441), pack-reused 6521
Réception d&apos;objets: 100% (7063/7063), 8.69 Mio | 5.39 Mio/s, fait.
Résolution des deltas: 100% (5047/5047), fait.
/tmp/git-search/cgit ~/dev/libre/songbooks/docs
README:    $ make get-git

$ git search &apos;make get-git&apos; https://git.zx2c4.com/cgit/
/tmp/git-search/cgit ~/dev/libre/songbooks/docs
README:    $ make get-git&lt;/pre&gt;
                  &lt;/td&gt;
                &lt;/tr&gt;
              &lt;/tbody&gt;
            &lt;/table&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;paragraph plaintext&quot;&gt;
          &lt;p&gt;&lt;a href=&quot;grep-online.html.1.txt&quot;&gt;plaintext&lt;/a&gt;&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;paragraph&quot;&gt;
          &lt;p&gt;Subsequent greps on the same repository are faster because no download is needed.&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;paragraph&quot;&gt;
          &lt;p&gt;When no argument is provided, it prints the usage text:&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;listingblock&quot;&gt;
          &lt;div class=&quot;content&quot;&gt;
            &lt;table&gt;
              &lt;tbody&gt;
                &lt;tr&gt;
                  &lt;td&gt;
                    &lt;pre class=&quot;lineno&quot;&gt;&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B3-L1&quot;
     href=&quot;#B3-L1&quot;&gt;1&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B3-L2&quot;
     href=&quot;#B3-L2&quot;&gt;2&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B3-L3&quot;
     href=&quot;#B3-L3&quot;&gt;3&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B3-L4&quot;
     href=&quot;#B3-L4&quot;&gt;4&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B3-L5&quot;
     href=&quot;#B3-L5&quot;&gt;5&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B3-L6&quot;
     href=&quot;#B3-L6&quot;&gt;6&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B3-L7&quot;
     href=&quot;#B3-L7&quot;&gt;7&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B3-L8&quot;
     href=&quot;#B3-L8&quot;&gt;8&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B3-L9&quot;
     href=&quot;#B3-L9&quot;&gt;9&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B3-L10&quot;
     href=&quot;#B3-L10&quot;&gt;10&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B3-L11&quot;
     href=&quot;#B3-L11&quot;&gt;11&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B3-L12&quot;
     href=&quot;#B3-L12&quot;&gt;12&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B3-L13&quot;
     href=&quot;#B3-L13&quot;&gt;13&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B3-L14&quot;
     href=&quot;#B3-L14&quot;&gt;14&lt;/a&gt;&lt;/pre&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                    &lt;pre&gt;$ git search
Missing argument REGEX_PATTERN.

Usage:
    /home/andreh/dev/libre/dotfiles/scripts/ad-hoc/git-search &amp;lt;REGEX_PATTERN&amp;gt; &amp;lt;REPOSITORY_URL&amp;gt;

      Arguments:
        REGEX_PATTERN     Regular expression that &quot;git grep&quot; can search
        REPOSITORY_URL    URL address that &quot;git clone&quot; can download the repository from

Examples:
    Searching &quot;make get-git&quot; in cgit repository:
        git search &apos;make get-git&apos; https://git.zx2c4.com/cgit/
        git search &apos;make get-git&apos; https://git.zx2c4.com/cgit/ -- $(git rev-list --all)&lt;/pre&gt;
                  &lt;/td&gt;
                &lt;/tr&gt;
              &lt;/tbody&gt;
            &lt;/table&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;paragraph plaintext&quot;&gt;
          &lt;p&gt;&lt;a href=&quot;grep-online.html.2.txt&quot;&gt;plaintext&lt;/a&gt;&lt;/p&gt;
        &lt;/div&gt;
    </content>
  </entry>
  <entry xml:lang="en">
    <title type="html">
      Search in git
    </title>
    <link type="text/html" rel="alternative" href="https://euandre.org/en/til/2020/08/16/git-search.html" title="Search in git" />
    <published>
      2020-08-16T00:00:00+00:00
    </published>
    <id>
      https://euandre.org/en/til/2020/08/16/git-search.html
    </id>
    <author>
      <name>
        EuAndreh
      </name>
      <email>
        eu@euandre.org
      </email>
    </author>
    <summary type="html">
        &lt;div id=&quot;preamble&quot;&gt;
          &lt;div class=&quot;sectionbody&quot;&gt;
            &lt;div class=&quot;paragraph&quot;&gt;
              &lt;p&gt;Here’s a useful trio to know about to help you search things in git:&lt;/p&gt;
            &lt;/div&gt;
    </summary>
    <content type="html" xml:base="en/til/2020/08/16/git-search.html">
        &lt;div id=&quot;preamble&quot;&gt;
          &lt;div class=&quot;sectionbody&quot;&gt;
            &lt;div class=&quot;paragraph&quot;&gt;
              &lt;p&gt;Here’s a useful trio to know about to help you search things in git:&lt;/p&gt;
            &lt;/div&gt;
            &lt;div class=&quot;olist arabic&quot;&gt;
              &lt;ol class=&quot;arabic&quot;&gt;
                &lt;li&gt;
                  &lt;p&gt;&lt;code&gt;git show &amp;lt;commit&amp;gt;&lt;/code&gt;&lt;/p&gt;
                &lt;/li&gt;
                &lt;li&gt;
                  &lt;p&gt;&lt;code&gt;git log --grep=&apos;&amp;lt;regexp&amp;gt;&apos;&lt;/code&gt;&lt;/p&gt;
                &lt;/li&gt;
                &lt;li&gt;
                  &lt;p&gt;&lt;code&gt;git grep &apos;&amp;lt;regexp&amp;gt;&apos; [commit]&lt;/code&gt;&lt;/p&gt;
                &lt;/li&gt;
              &lt;/ol&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;sect1&quot;&gt;
          &lt;h2 id=&quot;1-git-show-commit&quot;&gt;1. &lt;code&gt;git show &amp;lt;commit&amp;gt;&lt;/code&gt;&lt;a class=&quot;anchor&quot;
             href=&quot;#1-git-show-commit&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
          &lt;div class=&quot;sectionbody&quot;&gt;
            &lt;div class=&quot;paragraph&quot;&gt;
              &lt;p&gt;Show a specific commit and it’s diff:&lt;/p&gt;
            &lt;/div&gt;
            &lt;div class=&quot;listingblock&quot;&gt;
              &lt;div class=&quot;content&quot;&gt;
                &lt;table&gt;
                  &lt;tbody&gt;
                    &lt;tr&gt;
                      &lt;td&gt;
                        &lt;pre class=&quot;lineno&quot;&gt;&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L1&quot;
     href=&quot;#B1-L1&quot;&gt;1&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L2&quot;
     href=&quot;#B1-L2&quot;&gt;2&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L3&quot;
     href=&quot;#B1-L3&quot;&gt;3&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L4&quot;
     href=&quot;#B1-L4&quot;&gt;4&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L5&quot;
     href=&quot;#B1-L5&quot;&gt;5&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L6&quot;
     href=&quot;#B1-L6&quot;&gt;6&lt;/a&gt;&lt;/pre&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                        &lt;pre&gt;git show
# shows the latest commit
git show &amp;lt;commit&amp;gt;
# shows an specific &amp;lt;commit&amp;gt;
git show v1.2
# shows commit tagged with v1.2&lt;/pre&gt;
                      &lt;/td&gt;
                    &lt;/tr&gt;
                  &lt;/tbody&gt;
                &lt;/table&gt;
              &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class=&quot;paragraph plaintext&quot;&gt;
              &lt;p&gt;&lt;a href=&quot;git-search.html.0.txt&quot;&gt;plaintext&lt;/a&gt;&lt;/p&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;sect1&quot;&gt;
          &lt;h2 id=&quot;2-git-log-grepregexp&quot;&gt;2. &lt;code&gt;git log --grep=&apos;&amp;lt;regexp&amp;gt;&apos;&lt;/code&gt;&lt;a class=&quot;anchor&quot;
             href=&quot;#2-git-log-grepregexp&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
          &lt;div class=&quot;sectionbody&quot;&gt;
            &lt;div class=&quot;paragraph&quot;&gt;
              &lt;p&gt;Search through the commit messages:&lt;/p&gt;
            &lt;/div&gt;
            &lt;div class=&quot;listingblock&quot;&gt;
              &lt;div class=&quot;content&quot;&gt;
                &lt;table&gt;
                  &lt;tbody&gt;
                    &lt;tr&gt;
                      &lt;td&gt;
                        &lt;pre class=&quot;lineno&quot;&gt;&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L1&quot;
     href=&quot;#B2-L1&quot;&gt;1&lt;/a&gt;&lt;/pre&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                        &lt;pre&gt;git log --grep=&apos;refactor&apos;&lt;/pre&gt;
                      &lt;/td&gt;
                    &lt;/tr&gt;
                  &lt;/tbody&gt;
                &lt;/table&gt;
              &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class=&quot;paragraph plaintext&quot;&gt;
              &lt;p&gt;&lt;a href=&quot;git-search.html.1.txt&quot;&gt;plaintext&lt;/a&gt;&lt;/p&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;sect1&quot;&gt;
          &lt;h2 id=&quot;3-git-grep-regexp-commit&quot;&gt;3. &lt;code&gt;git grep &apos;&amp;lt;regexp&amp;gt;&apos; [commit]&lt;/code&gt;&lt;a class=&quot;anchor&quot;
             href=&quot;#3-git-grep-regexp-commit&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
          &lt;div class=&quot;sectionbody&quot;&gt;
            &lt;div class=&quot;paragraph&quot;&gt;
              &lt;p&gt;Search content in git history:&lt;/p&gt;
            &lt;/div&gt;
            &lt;div class=&quot;listingblock&quot;&gt;
              &lt;div class=&quot;content&quot;&gt;
                &lt;table&gt;
                  &lt;tbody&gt;
                    &lt;tr&gt;
                      &lt;td&gt;
                        &lt;pre class=&quot;lineno&quot;&gt;&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B3-L1&quot;
     href=&quot;#B3-L1&quot;&gt;1&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B3-L2&quot;
     href=&quot;#B3-L2&quot;&gt;2&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B3-L3&quot;
     href=&quot;#B3-L3&quot;&gt;3&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B3-L4&quot;
     href=&quot;#B3-L4&quot;&gt;4&lt;/a&gt;&lt;/pre&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                        &lt;pre&gt;git grep &apos;TODO&apos;
# search the repository for the &quot;TODO&quot; string
git grep &apos;TODO&apos; $(git rev-list --all)
# search the whole history for &quot;TODO&quot; string&lt;/pre&gt;
                      &lt;/td&gt;
                    &lt;/tr&gt;
                  &lt;/tbody&gt;
                &lt;/table&gt;
              &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class=&quot;paragraph plaintext&quot;&gt;
              &lt;p&gt;&lt;a href=&quot;git-search.html.2.txt&quot;&gt;plaintext&lt;/a&gt;&lt;/p&gt;
            &lt;/div&gt;
            &lt;div class=&quot;paragraph&quot;&gt;
              &lt;p&gt;And if you find an occurrence of the regexp in a specific commit and you want to browse the repository
              in that point in time, you can link:../14/browse-git.html[use git checkout for that].&lt;/p&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
    </content>
  </entry>
  <entry xml:lang="en">
    <title type="html">
      Browse a git repository at a specific commit
    </title>
    <link type="text/html" rel="alternative" href="https://euandre.org/en/til/2020/08/14/browse-git.html" title="Browse a git repository at a specific commit" />
    <published>
      2020-08-14T00:00:00+00:00
    </published>
    <id>
      https://euandre.org/en/til/2020/08/14/browse-git.html
    </id>
    <author>
      <name>
        EuAndreh
      </name>
      <email>
        eu@euandre.org
      </email>
    </author>
    <summary type="html">
        &lt;div id=&quot;preamble&quot;&gt;
          &lt;div class=&quot;sectionbody&quot;&gt;
            &lt;div class=&quot;paragraph&quot;&gt;
              &lt;p&gt;I commonly use tools like &lt;code&gt;git log&lt;/code&gt; together with &lt;code&gt;git show&lt;/code&gt; when inspecting
              past changes in a repository:&lt;/p&gt;
    </summary>
    <content type="html" xml:base="en/til/2020/08/14/browse-git.html">
        &lt;div id=&quot;preamble&quot;&gt;
          &lt;div class=&quot;sectionbody&quot;&gt;
            &lt;div class=&quot;paragraph&quot;&gt;
              &lt;p&gt;I commonly use tools like &lt;code&gt;git log&lt;/code&gt; together with &lt;code&gt;git show&lt;/code&gt; when inspecting
              past changes in a repository:&lt;/p&gt;
            &lt;/div&gt;
            &lt;div class=&quot;listingblock&quot;&gt;
              &lt;div class=&quot;content&quot;&gt;
                &lt;table&gt;
                  &lt;tbody&gt;
                    &lt;tr&gt;
                      &lt;td&gt;
                        &lt;pre class=&quot;lineno&quot;&gt;&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L1&quot;
     href=&quot;#B1-L1&quot;&gt;1&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L2&quot;
     href=&quot;#B1-L2&quot;&gt;2&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L3&quot;
     href=&quot;#B1-L3&quot;&gt;3&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B1-L4&quot;
     href=&quot;#B1-L4&quot;&gt;4&lt;/a&gt;&lt;/pre&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                        &lt;pre&gt;git log
# search for a the commit I&apos;m looking for
git show &amp;lt;my-commit&amp;gt;
# see the diff for the commit&lt;/pre&gt;
                      &lt;/td&gt;
                    &lt;/tr&gt;
                  &lt;/tbody&gt;
                &lt;/table&gt;
              &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class=&quot;paragraph plaintext&quot;&gt;
              &lt;p&gt;&lt;a href=&quot;browse-git.html.0.txt&quot;&gt;plaintext&lt;/a&gt;&lt;/p&gt;
            &lt;/div&gt;
            &lt;div class=&quot;paragraph&quot;&gt;
              &lt;p&gt;But I also wanted to not only be able to look at the diff of a specific commit, but to browse the
              whole repository at that specific commit.&lt;/p&gt;
            &lt;/div&gt;
            &lt;div class=&quot;paragraph&quot;&gt;
              &lt;p&gt;I used to accomplish it the &quot;brute force&quot; way: clone the whole repository in another folder and
              checkout the commit there:&lt;/p&gt;
            &lt;/div&gt;
            &lt;div class=&quot;listingblock&quot;&gt;
              &lt;div class=&quot;content&quot;&gt;
                &lt;table&gt;
                  &lt;tbody&gt;
                    &lt;tr&gt;
                      &lt;td&gt;
                        &lt;pre class=&quot;lineno&quot;&gt;&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L1&quot;
     href=&quot;#B2-L1&quot;&gt;1&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L2&quot;
     href=&quot;#B2-L2&quot;&gt;2&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B2-L3&quot;
     href=&quot;#B2-L3&quot;&gt;3&lt;/a&gt;&lt;/pre&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                        &lt;pre&gt;git clone &amp;lt;original-repo&amp;gt; /tmp/tmp-repo-clone
cd /tmp-repo-clone
git checkout &amp;lt;my-commit&amp;gt;&lt;/pre&gt;
                      &lt;/td&gt;
                    &lt;/tr&gt;
                  &lt;/tbody&gt;
                &lt;/table&gt;
              &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class=&quot;paragraph plaintext&quot;&gt;
              &lt;p&gt;&lt;a href=&quot;browse-git.html.1.txt&quot;&gt;plaintext&lt;/a&gt;&lt;/p&gt;
            &lt;/div&gt;
            &lt;div class=&quot;paragraph&quot;&gt;
              &lt;p&gt;But git itself allows we to specific the directory of the checkout by using the
              &lt;code&gt;--work-tree&lt;/code&gt; global git flag. This is what &lt;code&gt;man git&lt;/code&gt; says about it:&lt;/p&gt;
            &lt;/div&gt;
            &lt;div class=&quot;listingblock&quot;&gt;
              &lt;div class=&quot;content&quot;&gt;
                &lt;table&gt;
                  &lt;tbody&gt;
                    &lt;tr&gt;
                      &lt;td&gt;
                        &lt;pre class=&quot;lineno&quot;&gt;&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B3-L1&quot;
     href=&quot;#B3-L1&quot;&gt;1&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B3-L2&quot;
     href=&quot;#B3-L2&quot;&gt;2&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B3-L3&quot;
     href=&quot;#B3-L3&quot;&gt;3&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B3-L4&quot;
     href=&quot;#B3-L4&quot;&gt;4&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B3-L5&quot;
     href=&quot;#B3-L5&quot;&gt;5&lt;/a&gt;&lt;/pre&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                        &lt;pre&gt;--work-tree=&amp;lt;path&amp;gt;
    Set the path to the working tree. It can be an absolute path or a path relative to the current working
    directory. This can also be controlled by setting the GIT_WORK_TREE environment variable and the
    core.worktree configuration variable (see core.worktree in git-config(1) for a more detailed
    discussion).&lt;/pre&gt;
                      &lt;/td&gt;
                    &lt;/tr&gt;
                  &lt;/tbody&gt;
                &lt;/table&gt;
              &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class=&quot;paragraph plaintext&quot;&gt;
              &lt;p&gt;&lt;a href=&quot;browse-git.html.2.txt&quot;&gt;plaintext&lt;/a&gt;&lt;/p&gt;
            &lt;/div&gt;
            &lt;div class=&quot;paragraph&quot;&gt;
              &lt;p&gt;So it allows us to set the desired path of the working tree. So if we want to copy the contents of the
              current working tree into &lt;code&gt;copy/&lt;/code&gt;:&lt;/p&gt;
            &lt;/div&gt;
            &lt;div class=&quot;listingblock&quot;&gt;
              &lt;div class=&quot;content&quot;&gt;
                &lt;table&gt;
                  &lt;tbody&gt;
                    &lt;tr&gt;
                      &lt;td&gt;
                        &lt;pre class=&quot;lineno&quot;&gt;&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B4-L1&quot;
     href=&quot;#B4-L1&quot;&gt;1&lt;/a&gt;
&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B4-L2&quot;
     href=&quot;#B4-L2&quot;&gt;2&lt;/a&gt;&lt;/pre&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                        &lt;pre&gt;mkdir copy
git --work-tree=copy/ checkout .&lt;/pre&gt;
                      &lt;/td&gt;
                    &lt;/tr&gt;
                  &lt;/tbody&gt;
                &lt;/table&gt;
              &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class=&quot;paragraph plaintext&quot;&gt;
              &lt;p&gt;&lt;a href=&quot;browse-git.html.3.txt&quot;&gt;plaintext&lt;/a&gt;&lt;/p&gt;
            &lt;/div&gt;
            &lt;div class=&quot;paragraph&quot;&gt;
              &lt;p&gt;After that &lt;code&gt;copy/&lt;/code&gt; will contain a replica of the code in HEAD. But to checkout a specific,
              we need some extra parameters:&lt;/p&gt;
            &lt;/div&gt;
            &lt;div class=&quot;listingblock&quot;&gt;
              &lt;div class=&quot;content&quot;&gt;
                &lt;table&gt;
                  &lt;tbody&gt;
                    &lt;tr&gt;
                      &lt;td&gt;
                        &lt;pre class=&quot;lineno&quot;&gt;&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B5-L1&quot;
     href=&quot;#B5-L1&quot;&gt;1&lt;/a&gt;&lt;/pre&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                        &lt;pre&gt;git --work-tree=&amp;lt;dir&amp;gt; checkout &amp;lt;my-commit&amp;gt; -- .&lt;/pre&gt;
                      &lt;/td&gt;
                    &lt;/tr&gt;
                  &lt;/tbody&gt;
                &lt;/table&gt;
              &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class=&quot;paragraph plaintext&quot;&gt;
              &lt;p&gt;&lt;a href=&quot;browse-git.html.4.txt&quot;&gt;plaintext&lt;/a&gt;&lt;/p&gt;
            &lt;/div&gt;
            &lt;div class=&quot;paragraph&quot;&gt;
              &lt;p&gt;There’s an extra &lt;code&gt;– .&lt;/code&gt; at the end, which initially looks like we’re sending Morse signals
              to git, but we’re actually saying to &lt;code&gt;git-checkout&lt;/code&gt; which sub directory of
              &lt;code&gt;&amp;lt;my-commit&amp;gt;&lt;/code&gt; we want to look at. Which means we can do something like:&lt;/p&gt;
            &lt;/div&gt;
            &lt;div class=&quot;listingblock&quot;&gt;
              &lt;div class=&quot;content&quot;&gt;
                &lt;table&gt;
                  &lt;tbody&gt;
                    &lt;tr&gt;
                      &lt;td&gt;
                        &lt;pre class=&quot;lineno&quot;&gt;&lt;a class=&quot;code-line-anchor&quot;
     id=&quot;B6-L1&quot;
     href=&quot;#B6-L1&quot;&gt;1&lt;/a&gt;&lt;/pre&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                        &lt;pre&gt;git --work-tree=&amp;lt;dir&amp;gt; checkout &amp;lt;my-commit&amp;gt; -- src/&lt;/pre&gt;
                      &lt;/td&gt;
                    &lt;/tr&gt;
                  &lt;/tbody&gt;
                &lt;/table&gt;
              &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class=&quot;paragraph plaintext&quot;&gt;
              &lt;p&gt;&lt;a href=&quot;browse-git.html.5.txt&quot;&gt;plaintext&lt;/a&gt;&lt;/p&gt;
            &lt;/div&gt;
            &lt;div class=&quot;paragraph&quot;&gt;
              &lt;p&gt;And with that &lt;code&gt;&amp;lt;dir&amp;gt;&lt;/code&gt; will only contain what was inside &lt;code&gt;src/&lt;/code&gt; at
              &lt;code&gt;&amp;lt;commit&amp;gt;&lt;/code&gt;.&lt;/p&gt;
            &lt;/div&gt;
            &lt;div class=&quot;paragraph&quot;&gt;
              &lt;p&gt;After any of those checkouts, you have to &lt;code&gt;git reset .&lt;/code&gt; to reset your current staging area
              back to what it was before the checkout.&lt;/p&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;sect1&quot;&gt;
          &lt;h2 id=&quot;references&quot;&gt;References&lt;a class=&quot;anchor&quot;
             href=&quot;#references&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
          &lt;div class=&quot;sectionbody&quot;&gt;
            &lt;div class=&quot;olist arabic&quot;&gt;
              &lt;ol class=&quot;arabic&quot;&gt;
                &lt;li&gt;
                  &lt;p&gt;&lt;a href=&quot;https://stackoverflow.com/a/16493707&quot;&gt;GIT: Checkout to a specific folder&lt;/a&gt;
                  (StackOverflow)&lt;/p&gt;
                &lt;/li&gt;
              &lt;/ol&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
    </content>
  </entry>
</feed>
