Gustavo Huarcaya: Githttps://gahd.net/feed/Git/2020-08-02T20:52:48.735899+00:00Latest posts in: GitGustavo Huarcaya - https://gahd.netColorear 'git log' y 'git diff' en la terminal2017-08-26T19:45:28+00:002020-08-02T20:52:48.735899+00:00GustavoGustavo%20Huarcayahttps://gahd.net/git/colorear-git-log-y-git-diff-en-la-terminal/<p>He tenido el mismo problema en Slackware y FreeBSD.</p>
<p>Al querer ver el log de commits mediante <code>git log</code> o ver las diferencias con un <code>git diff</code> desde la terminal:</p>
<pre><code>[diavolo@mikasa:djangoproject.com]$ git log --oneline</code></pre>
<p>En lugar de ver algo como esto:</p>
<pre><code>ff4e711 (HEAD -> master, origin/master, origin/HEAD) Fixed typo in ProfileForm docstring.
8df1aaa Fixed CSRF token leak in donate form if JavaScript is disabled.
fbfeb6a Updated links to https.
8812595 Added 2017 PyCharm fundraiser banners.
d05033b Fixed #782 -- Added Django desktop wallpaper.</code></pre>
<p>Veía un conjunto de caracteres de escape que usa git para colorear los commits combinados con el log de commits.</p>
<pre><code>ESC[33mff4e711ESC[mESC[33m (ESC[mESC[1;36mHEAD -> ESC[mESC[1;32mmasterESC[mESC[33m, ESC[mESC[1;31morigin/masterESC[mESC[33m, ESC[mESC[1;31morigin/HEADESC[mESC[33m) ESC[m Fixed typo in ProfileForm docstring.
ESC[33m8df1aaaESC[m Fixed CSRF token leak in donate form if JavaScript is disabled.
ESC[33mfbfeb6aESC[m Updated links to https.
ESC[33m8812595ESC[m Added 2017 PyCharm fundraiser banners.
ESC[33md05033bESC[m Fixed #782 -- Added Django desktop wallpaper.</code></pre>
<p>El problema es que resulta incomodo y poco práctico para ver un historial.</p>
<figure><img class="ui image" src="/media/2020/08/git-log-48cae655-29d7-4912-bd2c-937cf7328c07.png" alt="git log" />
<figcaption>Figura 1: git log con caracteres de escape.</figcaption></figure><p>Para solucionar esto, solo hay que ejecutar lo siguiente para configurar el <code>core.pager</code> de git:</p>
<pre><code>[diavolo@mikasa:djangoproject.com]$ git config --global core.pager "less -R"</code></pre>
<p>Y desde ahora, cada vez que se desee ver el log de commits, o el diferencial de cambios, se visualizará un log a colores. Como debió de estar desde el inicio.</p>
<figure><img class="ui image" src="/media/2020/08/git-log-color-01198355-c390-49da-b38a-3eb3a0472906.png" alt="git log a colores" />
<figcaption>Figura 2: git log a colores.</figcaption></figure><h3>Fuentes</h3>
<ul>
<li><a href="https://git.wiki.kernel.org/index.php/GitFaq#Why_does_diff.2Flog_not_show_color.2C_even_though_I_enabled_it.3F" title=" Why does diff/log not show color, even though I enabled it? ">Why does diff/log not show color, even though I enabled it? </a></li>
</ul>
https://gahd.net/git/colorear-git-log-y-git-diff-en-la-terminal/Gustavo Huarcaya - https://gahd.net