<?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>DEV Community: Rahul Krishna</title>
    <description>The latest articles on DEV Community by Rahul Krishna (@rahulkrrrishna).</description>
    <link>https://dev.to/rahulkrrrishna</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%2F276965%2Fd180684f-6eba-4f62-988a-9fdc2f2e87e2.jpeg</url>
      <title>DEV Community: Rahul Krishna</title>
      <link>https://dev.to/rahulkrrrishna</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rahulkrrrishna"/>
    <language>en</language>
    <item>
      <title>Stash as a Commit</title>
      <dc:creator>Rahul Krishna</dc:creator>
      <pubDate>Wed, 22 Nov 2023 11:09:53 +0000</pubDate>
      <link>https://dev.to/rahulkrrrishna/stash-as-a-commit-4cdi</link>
      <guid>https://dev.to/rahulkrrrishna/stash-as-a-commit-4cdi</guid>
      <description>&lt;p&gt;Originally written at: &lt;a href="https://rahulkrrrishna.xyz/notes/2023/10/31/stash-as-a-commit.html" rel="noopener noreferrer"&gt;https://rahulkrrrishna.xyz/notes/2023/10/31/stash-as-a-commit.html&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  What is a Stash?
&lt;/h3&gt;




&lt;p&gt;From Julia Evans’ blog article titled &lt;strong&gt;Some miscellaneous git facts&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;👉🏽 *&lt;strong&gt;*the stash is a bunch of commits**&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When I run &lt;code&gt;git stash&lt;/code&gt; to stash my changes, I’ve always been a bit confused about where those changes actually went. It turns out that when you run &lt;code&gt;git stash&lt;/code&gt;, git makes some commits with your changes and labels them with a reference called &lt;code&gt;stash&lt;/code&gt; (in &lt;code&gt;.git/refs/stash&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;Let’s stash this blog post and look at the log of the &lt;code&gt;stash&lt;/code&gt; reference:&lt;/p&gt;


&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git log stash --oneline
6cb983fe (refs/stash) WIP on main: c6ee55ed wip
2ff2c273 index on main: c6ee55ed wip
... some more stuff

&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Now we can look at the commit &lt;code&gt;2ff2c273&lt;/code&gt; to see what it contains:&lt;/p&gt;


&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git show 2ff2c273  --stat
commit 2ff2c273357c94a0087104f776a8dd28ee467769
Author: Julia Evans &amp;lt;julia@jvns.ca&amp;gt;
Date:   Fri Oct 20 14:49:20 2023 -0400

   index on main: c6ee55ed wip

content/post/2023-10-20-some-miscellaneous-git-facts.markdown | 40 ++++++++++++++++++++++++++++++++++++++++

&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Unsurprisingly, it contains this blog post. Makes sense!&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git stash&lt;/code&gt; actually creates 2 separate commits: one for the index, and one for your changes that you haven’t staged yet. I found this kind of heartening because I’ve been working on a tool to snapshot and restore the state of a git repository (that I may or may not ever release) and I came up with a very similar design, so that made me feel better about my choices.&lt;/p&gt;

&lt;p&gt;Apparently older commits in the stash are stored in the reflog.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  The Rationale Behind Preferring Commit Over Stash
&lt;/h3&gt;




&lt;p&gt;For individuals accustomed to the command-line interface of Git, the concept of committing instead of stashing may seem unconventional. However, when one's Git workflow is seamlessly integrated into their Integrated Development Environment (IDE), particularly Visual Studio Code, this approach becomes highly beneficial.&lt;/p&gt;

&lt;h4&gt;
  
  
  The User Interface of Atom
&lt;/h4&gt;

&lt;p&gt;The user interface of Atom is commendable, particularly due to its tri-pane design that consistently displays the File Explorer, Code, and Git.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvkfcpdzx4b2iaz081u3s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvkfcpdzx4b2iaz081u3s.png" alt="The Atom UI with File Explorer, Code Area and Git/Github Panel" width="800" height="499"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Atom UI with File Explorer, Code Area and Git/Github Panel&lt;/p&gt;

&lt;p&gt;This design is advantageous as it continually updates a list of changes made to files on the right side of the screen, providing a general overview of the magnitude of your modifications. This visibility encourages experimental changes, which can be easily cherry-picked or discarded.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fglhgblatnq6v8dffvyyu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fglhgblatnq6v8dffvyyu.png" alt="Atom Git Pane" width="345" height="809"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Atom Git Pane&lt;/p&gt;

&lt;h3&gt;
  
  
  The Workflow in Atom
&lt;/h3&gt;




&lt;p&gt;Consider a scenario where you are working on &lt;code&gt;feature-branch-1&lt;/code&gt; and need to switch to the &lt;code&gt;master&lt;/code&gt; branch. Typically, you would stash your changes in &lt;code&gt;feature-branch-1&lt;/code&gt;. However, Atom provides an alternative commit method.&lt;/p&gt;


&lt;div&gt;
  &lt;iframe src="https://loom.com/embed/3b5ae799bb104aa5891ed51a92d5f6ca"&gt;
  &lt;/iframe&gt;
&lt;/div&gt;


&lt;h3&gt;
  
  
  Visual Studio Code: A Comparison
&lt;/h3&gt;




&lt;p&gt;By default, Visual Studio Code does not offer the same layout as Atom. However, this is arguably advantageous, and a similar workflow to Atom can be achieved in Visual Studio Code. This can be done by enabling a Secondary Side Bar and moving your "Source Control" and "Commits" to the second pane.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhinz8ijlbbixrqjx0byh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhinz8ijlbbixrqjx0byh.png" alt="Untitled" width="800" height="271"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fve7f6djia7b8vpmubd32.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fve7f6djia7b8vpmubd32.png" alt="A lot more cluttered than my Atom. But it also does a lot more than Atom!" width="800" height="472"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A lot more cluttered than my Atom. But it also does a lot more than Atom!&lt;/p&gt;

&lt;h3&gt;
  
  
  The Workflow in Visual Studio Code
&lt;/h3&gt;





&lt;div&gt;
  &lt;iframe src="https://loom.com/embed/a1fa5c8bebd74fb889ae26dbbfcf63ee"&gt;
  &lt;/iframe&gt;
&lt;/div&gt;


&lt;h3&gt;
  
  
  Additional: Command Line Approach
&lt;/h3&gt;





&lt;div&gt;
  &lt;iframe src="https://loom.com/embed/70c3d90ac8a64c2aaae010394174a8bb"&gt;
  &lt;/iframe&gt;
&lt;/div&gt;


&lt;h3&gt;
  
  
  The Merits of Stash Commit
&lt;/h3&gt;




&lt;p&gt;The primary advantage of a stash commit is that it is local to a branch. This is particularly useful when working on multiple features and needing to stash changes to switch branches (often to master to create a new branch). Upon returning, the stash commit is visible, allowing you to resume where you left off. This is especially helpful when revisiting a branch after a significant period, as remembering that you stashed some code may not be evident.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Argument for Stash
&lt;/h3&gt;




&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;git stash&lt;/code&gt; effectively clears your branch of changes for later use, which is necessary if you do not have a branch to perform a &lt;code&gt;stash commit&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;If you have a piece of code that is frequently needed but cannot be committed, &lt;code&gt;git stash&lt;/code&gt; is the preferred method.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  References
&lt;/h3&gt;




&lt;p&gt;Julia Evans’ Blog Article: &lt;a href="https://jvns.ca/blog/2023/10/20/some-miscellaneous-git-facts/" rel="noopener noreferrer"&gt;https://jvns.ca/blog/2023/10/20/some-miscellaneous-git-facts/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>git</category>
      <category>vscode</category>
      <category>development</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
