<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Mike Moore</title>
    <description>The latest articles on Forem by Mike Moore (@miketmoore).</description>
    <link>https://forem.com/miketmoore</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F52020%2F889662e5-fe45-42b9-9e3c-21b568f99ed5.jpeg</url>
      <title>Forem: Mike Moore</title>
      <link>https://forem.com/miketmoore</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/miketmoore"/>
    <language>en</language>
    <item>
      <title>Git Diff Cached</title>
      <dc:creator>Mike Moore</dc:creator>
      <pubDate>Mon, 13 Jul 2020 16:08:44 +0000</pubDate>
      <link>https://forem.com/miketmoore/git-diff-cached-3a06</link>
      <guid>https://forem.com/miketmoore/git-diff-cached-3a06</guid>
      <description>&lt;p&gt;Recently, I've been doing some semi-experimental UI work, where I know what changes I need to make but some of the details aren't clear to me. So, I end up making the changes, but I've changed more files than I want to include in a single commit. Using git, there are a few different ways to pick and choose which changes should be staged for a commit. One of the most common methods I use goes like this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;make changes&lt;/li&gt;
&lt;li&gt;stage &lt;em&gt;some&lt;/em&gt; of the changes for commit (using &lt;code&gt;git add&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;reviewing the staged (added) changes&lt;/li&gt;
&lt;li&gt;making the commit&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this post, I am briefly going to explain how I do step #3 above, "reviewing the staged (added) changes".&lt;/p&gt;

&lt;p&gt;Basically, if I have just staged changes using &lt;code&gt;git add&lt;/code&gt;, then a normal &lt;code&gt;git diff&lt;/code&gt; won't show me those changes. It will only show me the changes that have &lt;em&gt;not&lt;/em&gt; been staged. So, I add the &lt;code&gt;--cached&lt;/code&gt; option:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git diff --cached
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;...and, voila! I can see the diff of the changes that are currently staged for commit.&lt;/p&gt;

&lt;p&gt;If you are new to git, this is how you can scroll up and down, and exit the diff, using the following keyboard shortcuts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
j scroll down&lt;/li&gt;
&lt;li&gt;
k scroll up&lt;/li&gt;
&lt;li&gt;
q quit&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, if I'm satisfied with the changes, I can go ahead and commit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git commit -m 'my commit message'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;...or, if I realize that the changes should not be combined, I can "un-stage" them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git reset HEAD .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From the official docs:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This form is to view the changes you staged for the next commit relative to the named .&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://git-scm.com/docs/git-diff#Documentation/git-diff.txt-emgitdiffemltoptionsgt--cachedltcommitgt--ltpathgt82308203"&gt;https://git-scm.com/docs/git-diff#Documentation/git-diff.txt-emgitdiffemltoptionsgt--cachedltcommitgt--ltpathgt82308203&lt;/a&gt;&lt;/p&gt;

</description>
      <category>git</category>
    </item>
    <item>
      <title>Git Commit Amend</title>
      <dc:creator>Mike Moore</dc:creator>
      <pubDate>Sat, 11 Jul 2020 18:33:26 +0000</pubDate>
      <link>https://forem.com/miketmoore/git-commit-amend-54oo</link>
      <guid>https://forem.com/miketmoore/git-commit-amend-54oo</guid>
      <description>&lt;p&gt;I want to start writing regularly again so I thought I'd share one of my favorite git commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git commit --amend --no-edit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I use this command to combine just added changes into the last commit I made. &lt;/p&gt;

&lt;p&gt;Here is a scenario:&lt;/p&gt;

&lt;p&gt;Let's say I have just edited a file and already commited it, but then I realize I made a typo before I push my changes. I can edit the file, add the change (stage it), and then run &lt;code&gt;git commit --amend --no-edit&lt;/code&gt;. This will put my typo fix into the latest commit and replace that commit's hash with a new hash. This is usually referred to as "rewriting history" in git. Now, I can push my change up as one commit, instead of two. &lt;/p&gt;

&lt;p&gt;Here is what the official docs say about the &lt;code&gt;--amend&lt;/code&gt; option:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Replace the tip of the current branch by creating a new commit.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---amend"&gt;https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---amend&lt;/a&gt;&lt;/p&gt;

</description>
      <category>git</category>
    </item>
  </channel>
</rss>
