<?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: Sean Larkin</title>
    <description>The latest articles on Forem by Sean Larkin (@thelarkinn).</description>
    <link>https://forem.com/thelarkinn</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%2F879%2F3408176.jpeg</url>
      <title>Forem: Sean Larkin</title>
      <link>https://forem.com/thelarkinn</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/thelarkinn"/>
    <language>en</language>
    <item>
      <title>One Crate a Day: has-flag</title>
      <dc:creator>Sean Larkin</dc:creator>
      <pubDate>Tue, 24 Jan 2023 18:13:58 +0000</pubDate>
      <link>https://forem.com/thelarkinn/one-rust-crate-a-day-has-flag-26ph</link>
      <guid>https://forem.com/thelarkinn/one-rust-crate-a-day-has-flag-26ph</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kAk1ue6d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s0mrdc53fblhni1znfyw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kAk1ue6d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s0mrdc53fblhni1znfyw.png" alt="Pixel art image of a Crab reading a book" width="880" height="880"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Welcome to &lt;em&gt;"One Crate a Day"&lt;/em&gt;, my daily journal as I dive into the world of Rust programming. As a JavaScript developer with a background in open-source, I've decided to take on the challenge of re-writing popular JavaScript packages for the Rust community. &lt;/p&gt;

&lt;p&gt;Here are a few tl;dr goals I have for this project: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;👨‍🎓Learn Rust &amp;amp; Popular JavaScript modules&lt;/li&gt;
&lt;li&gt;📦Contribute to the Rust community by publishing new Crates&lt;/li&gt;
&lt;li&gt;👨‍🏫Share my learnings, tips, and best practices with you&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;If you've come here to learn how to install, start Rust from scratch, or setup the toolchain for your IDE/environment, see &lt;a href="https://doc.rust-lang.org/stable/book/title-page.html"&gt;the Rust Handbook&lt;/a&gt;! Otherwise, lets dive in!&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Crate #1: &lt;a href="https://crates.io/crates/has-env-flag"&gt;&lt;code&gt;has-env-flag&lt;/code&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Original Package: &lt;a href="https://github.com/sindresorhus/has-flag"&gt;sindresorhus/has-flag&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/sindresorhus"&gt;Sindre&lt;/a&gt;'s JavaScript packages exemplify the concepts of single purpose and reusability. Often times only implemented as a single exported function. &lt;code&gt;has-flag&lt;/code&gt; is no different in this regard. &lt;/p&gt;

&lt;h3&gt;
  
  
  Review
&lt;/h3&gt;

&lt;p&gt;This single function module allows developers to quickly detect the presence of a specific flag in the argv (arguments passed to the script/binary that was run). The code for the module is as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;process&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// eslint-disable-line node/prefer-global/process&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;hasFlag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;flag&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;argv&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;prefix&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;flag&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;startsWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;-&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;flag&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;-&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;--&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;position&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;indexOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;prefix&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;flag&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;terminatorPosition&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;indexOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;--&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;position&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;terminatorPosition&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;position&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;terminatorPosition&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;With this module, we can easily check for the presence of a specific argument ("flag") based on what was passed into our script. Here's an example from the &lt;a href="https://github.com/sindresorhus/has-flag"&gt;README&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// foo.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;hasFlag&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;has-flag&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;hasFlag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;unicorn&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//=&amp;gt; true&lt;/span&gt;

&lt;span class="nx"&gt;hasFlag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;--unicorn&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//=&amp;gt; true&lt;/span&gt;

&lt;span class="nx"&gt;hasFlag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;f&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//=&amp;gt; true&lt;/span&gt;

&lt;span class="nx"&gt;hasFlag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;-f&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//=&amp;gt; true&lt;/span&gt;

&lt;span class="nx"&gt;hasFlag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;foo=bar&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//=&amp;gt; true&lt;/span&gt;

&lt;span class="nx"&gt;hasFlag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;foo&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//=&amp;gt; false&lt;/span&gt;

&lt;span class="nx"&gt;hasFlag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;rainbow&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//=&amp;gt; false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;node foo.js &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="nt"&gt;--unicorn&lt;/span&gt; &lt;span class="nt"&gt;--foo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;bar &lt;span class="nt"&gt;--&lt;/span&gt; &lt;span class="nt"&gt;--rainbow&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Approach
&lt;/h2&gt;

&lt;p&gt;To start my journey, I decided to craft my unit tests first. This way, I could work backwards until I had my solution. &lt;/p&gt;

&lt;h3&gt;
  
  
  Learning #1: Cargo uses Conventions
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://doc.rust-lang.org/cargo/"&gt;Cargo&lt;/a&gt;, which is the out-of-the-box tool for running tests, installing packages/dependencies, and more, has &lt;strong&gt;conventions&lt;/strong&gt; for building libraries versus binaries. &lt;/p&gt;

&lt;p&gt;By default, Cargo looks for one of two conventions in the workspace:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Libraries: If you are building a Rust library ("Crate"), Cargo will enforce the presence of &lt;code&gt;src/lib.rs&lt;/code&gt; in your workspace.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Binaries: If you are building a Rust binary, Cargo will enforce the presence of &lt;code&gt;src/main.rs&lt;/code&gt;. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I love this! Every time I crack open a Rust project, I know &lt;em&gt;exactly&lt;/em&gt; where to start/begin reading code. &lt;/p&gt;

&lt;h3&gt;
  
  
  Learning #2: How to write tests
&lt;/h3&gt;

&lt;p&gt;Next, I learned how to write tests in Rust. From all of the packages I've looked at, and according to the &lt;a href="https://doc.rust-lang.org/book/ch11-01-writing-tests.html"&gt;Rust Handbook&lt;/a&gt;, unit tests are written &lt;em&gt;in the same file&lt;/em&gt;! Additionally, you'll see the usage of Macros heavily in Rust tests. &lt;em&gt;Macros are a powerful tool for creating code expansion at compile time, saving you from writing lines of boilerplate code.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Take the following test I wrote in my module as an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Macro for setting up a test module&lt;/span&gt;
&lt;span class="nd"&gt;#[cfg(test)]&lt;/span&gt;
&lt;span class="k"&gt;mod&lt;/span&gt; &lt;span class="n"&gt;tests&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Gives access to outer scope (not just the `pub fn`'s)&lt;/span&gt;
    &lt;span class="c1"&gt;// great to test functions used in Dependency Injection&lt;/span&gt;
    &lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// Macro that turns a function into a unit test&lt;/span&gt;
    &lt;span class="nd"&gt;#[test]&lt;/span&gt;
    &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;args_with_value_not_matching_double_dash&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nd"&gt;vec!&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"--foo"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"--unicorn=rainbow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"--bar"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;expected_value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"unicorn=rainbow"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="nd"&gt;assert!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;_has_flag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="nf"&gt;.into_iter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nn"&gt;ToString&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;to_string&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="n"&gt;expected_value&lt;/span&gt;
        &lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://doc.rust-lang.org/stable/book/ch11-03-test-organization.html?highlight=%23%5Bcfg(test)#the-tests-module-and-cfgtest"&gt;&lt;code&gt;#[cfg(test)]&lt;/code&gt; macro&lt;/a&gt;: This is our macro for setting up our test module. It instructs Rust to compile and run the test code only when you run &lt;code&gt;cargo test&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://doc.rust-lang.org/stable/book/ch11-01-writing-tests.html"&gt;&lt;code&gt;#[test]&lt;/code&gt; macro&lt;/a&gt;: This macro converts the function into a unit test! You will use macros like &lt;code&gt;assert!()&lt;/code&gt; or &lt;code&gt;assert_eq!()&lt;/code&gt; to validate the results of the code you want to test.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;use super::*&lt;/code&gt;: Exposes the outer scope to your &lt;a href="https://doc.rust-lang.org/stable/book/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.html"&gt;inner test module&lt;/a&gt;. The glob allows &lt;em&gt;anything&lt;/em&gt; defined in the outer scope to be used in your test functions (anything not defined with &lt;code&gt;pub fn&lt;/code&gt;)!&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Learning 3: Working with &lt;code&gt;std::env&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;After implementing the tests I decided to take a crack at writing this module. Much thanks to &lt;a href="https://twitter.com/steveklabnik"&gt;Steve Klabnik&lt;/a&gt;, who helped me with getting the types for the function and setting up dependency injection, this was the &lt;strong&gt;first&lt;/strong&gt; iteration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;has_flag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;flag&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;_has_flag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nn"&gt;std&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nn"&gt;env&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;args&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;flag&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="n"&gt;_has_flag&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;I&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Iterator&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Item&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;I&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;flag&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;prefix&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;flag&lt;/span&gt;&lt;span class="nf"&gt;.starts_with&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sc"&gt;'-'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s"&gt;""&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;flag&lt;/span&gt;&lt;span class="nf"&gt;.len&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="s"&gt;"-"&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="s"&gt;"--"&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;position&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="nf"&gt;.position&lt;/span&gt;&lt;span class="p"&gt;(|&lt;/span&gt;&lt;span class="n"&gt;arg&lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="n"&gt;arg&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nd"&gt;format!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{}{}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;prefix&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;flag&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;terminator_position&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="nf"&gt;.position&lt;/span&gt;&lt;span class="p"&gt;(|&lt;/span&gt;&lt;span class="n"&gt;arg&lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="n"&gt;arg&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s"&gt;"--"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;position&lt;/span&gt;&lt;span class="nf"&gt;.is_some&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;terminator_position&lt;/span&gt;&lt;span class="nf"&gt;.is_some&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;||&lt;/span&gt; &lt;span class="n"&gt;position&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;terminator_position&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://doc.rust-lang.org/std/env/fn.args.html"&gt;&lt;code&gt;std::env::args()&lt;/code&gt;&lt;/a&gt;: This is how you can access &lt;code&gt;argv&lt;/code&gt; or arguments that the program was started with. &lt;code&gt;std&lt;/code&gt; is the &lt;a href="https://doc.rust-lang.org/std/index.html"&gt;Rust standard library&lt;/a&gt; and is available to all Rust crates by default.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.position"&gt;&lt;code&gt;.position()&lt;/code&gt;&lt;/a&gt;: Searches for an element in an iterator, and returns its index. I saw this as   comparable to &lt;code&gt;.indexOf&lt;/code&gt; in JavaScript. &lt;strong&gt;However I made some mistakes in my code using this and I'll explain why&lt;/strong&gt;.  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://doc.rust-lang.org/std/option/enum.Option.html"&gt;&lt;code&gt;.is_some()&lt;/code&gt; &amp;amp; &lt;code&gt;is_none()&lt;/code&gt;&lt;/a&gt;: There is no concept of &lt;code&gt;null&lt;/code&gt; in Rust. Rather, Option is a type which is meant to handle the no value being returned. In a few parts of our code, we don't &lt;em&gt;really care what the index is&lt;/em&gt;, rather if the index &lt;em&gt;exists&lt;/em&gt;. &lt;code&gt;.is_some()&lt;/code&gt; is the perfect usage for that here. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Learning 4: Mutability and Bugs!
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;This code that I initially committed and published actually had a few bugs!&lt;/em&gt; However, my initial tests were passing. I had created a &lt;a href="https://github.com/TheLarkInn/has-flag/issues/4"&gt;GitHub Issue&lt;/a&gt; to come back when I had time and implement &lt;a href="https://github.com/sindresorhus/has-flag/blob/0c7d032214c51d14b458364c9f6575ea9afa08b1/test.js#L4-L16"&gt;all of the tests&lt;/a&gt; from &lt;code&gt;has-flag&lt;/code&gt;'s test suite.&lt;/p&gt;

&lt;p&gt;My &lt;a href="https://github.com/TheLarkInn/has-flag/pull/5"&gt;PR introducing the full tests&lt;/a&gt; was failing so I knew there must be a bug in the code itself. After getting some feedback from the "Beginners" channel on &lt;a href="https://discord.gg/rust-lang"&gt;The Rust Programming Language Discord&lt;/a&gt;, I started to realize some of the mistakes I had made. Here is the updated code which passed tests:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;has_flag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;flag&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;_has_flag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nn"&gt;std&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nn"&gt;env&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;args&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;flag&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="n"&gt;_has_flag&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;I&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Iterator&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Item&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;I&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;flag&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;prefix&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;flag&lt;/span&gt;&lt;span class="nf"&gt;.starts_with&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sc"&gt;'-'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s"&gt;""&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;flag&lt;/span&gt;&lt;span class="nf"&gt;.len&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s"&gt;"-"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s"&gt;"--"&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;formatted_flag&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nd"&gt;format!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{}{}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;prefix&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;flag&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="nf"&gt;.take_while&lt;/span&gt;&lt;span class="p"&gt;(|&lt;/span&gt;&lt;span class="n"&gt;arg&lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="n"&gt;arg&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="s"&gt;"--"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nf"&gt;.any&lt;/span&gt;&lt;span class="p"&gt;(|&lt;/span&gt;&lt;span class="n"&gt;arg&lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="n"&gt;arg&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;formatted_flag&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;mut args&lt;/code&gt; =&amp;gt; &lt;code&gt;args&lt;/code&gt;: The first &lt;strong&gt;code smell&lt;/strong&gt; I should have noticed when I wrote my first iteration, was that the Rust compiler was forcing me to add &lt;code&gt;mut&lt;/code&gt; next to my &lt;code&gt;args&lt;/code&gt; parameter for the function. This didn't make sense to me because &lt;code&gt;mut&lt;/code&gt; is only needed if I am mutating &lt;code&gt;args&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;.position()&lt;/code&gt; mutates: This led me to noticing that &lt;code&gt;.position()&lt;/code&gt; was &lt;em&gt;not&lt;/em&gt; the function I wanted to use. &lt;code&gt;.position()&lt;/code&gt; &lt;em&gt;consumes&lt;/em&gt; items in the iterator until the predicate is matched. So the code determining &lt;code&gt;terminator_position&lt;/code&gt; was actually accessing a mutated &lt;code&gt;args&lt;/code&gt;. All my tests involving the &lt;code&gt;--&lt;/code&gt; args terminator were failing as a result! &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://doc.rust-lang.org/std/iter/struct.TakeWhile.html#method.take_while"&gt;&lt;code&gt;.take_while()&lt;/code&gt;&lt;/a&gt;: Takes an iterator, and runs through it &lt;em&gt;until&lt;/em&gt; the predicate is true, and then &lt;em&gt;returns&lt;/em&gt; an iterator of those items up until the predicate. &lt;strong&gt;I think of this similar to an iterator &lt;em&gt;filter&lt;/em&gt;&lt;/strong&gt;. This was perfect for us to use here because we don't want to match args passed &lt;em&gt;after&lt;/em&gt; the &lt;code&gt;--&lt;/code&gt; terminator. It also massively simplified our code!&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Ship it🎉
&lt;/h2&gt;

&lt;p&gt;This iteration passed all of our tests and I was able to happily merge and publish a &lt;a href="https://github.com/TheLarkInn/has-flag/releases/tag/0.1.2"&gt;new release of &lt;code&gt;has-env-flag&lt;/code&gt;&lt;/a&gt;. As I continue to &lt;a href="https://github.com/users/TheLarkInn/projects/1/views/1?pane=issue&amp;amp;itemId=18591212"&gt;work on this journal&lt;/a&gt;, I will encounter many new challenges and learnings about Rust, and I can't wait to share them with you. &lt;/p&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/stars/TheLarkInn/lists/my-rust-projects"&gt;My Rust Crates&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/users/TheLarkInn/projects/1"&gt;Rust Journey GitHub Project&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/TheLarkInn/has-flag"&gt;&lt;code&gt;has-env-flag&lt;/code&gt; project on GitHub&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/sindresorhus/has-flag"&gt;&lt;code&gt;sindresorhus/has-flag&lt;/code&gt; on GitHub&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>rust</category>
      <category>javascript</category>
      <category>nodemodules</category>
      <category>testing</category>
    </item>
    <item>
      <title>Split a commit into 2 commits with `git rebase`</title>
      <dc:creator>Sean Larkin</dc:creator>
      <pubDate>Mon, 05 Dec 2022 18:31:40 +0000</pubDate>
      <link>https://forem.com/thelarkinn/split-a-commit-into-2-commits-with-git-rebase-31ee</link>
      <guid>https://forem.com/thelarkinn/split-a-commit-into-2-commits-with-git-rebase-31ee</guid>
      <description>&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;p&gt;Git is a powerful version control system that allows developers to track and manage changes to their code. One of the key features of Git is the ability to use interactive rebasing to modify the history of a branch.&lt;/p&gt;

&lt;p&gt;Interactive rebasing allows you to edit, reorder, and split commits in a branch. This can be useful when you need to clean up your branch history, or when you want to split a commit that contains changes for multiple files into separate commits.&lt;/p&gt;

&lt;h2&gt;
  
  
  pnpm, yarn, npm lockfiles
&lt;/h2&gt;

&lt;p&gt;Have you ever had to &lt;code&gt;git rebase&lt;/code&gt; in your project but consistently had merge conflicts in your pnpm/yarn/npm lockfiles? You may have heard the advice to 'always commit your lockfile in an isolated commit'. &lt;/p&gt;

&lt;p&gt;This is because you can use the &lt;code&gt;drop&lt;/code&gt; command in an interactive rebase to remove the commit so you can regenerate the lockfile after your rebase. &lt;/p&gt;

&lt;p&gt;Often times, I forget this and sometimes I end up with multiple files (including my lockfile) inside my single commit and now I cannot &lt;code&gt;drop&lt;/code&gt; it. &lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started
&lt;/h2&gt;

&lt;p&gt;In this tutorial, we will show you how to split a commit during an interactive git rebase. We will use a simple example to illustrate the steps involved in splitting a commit.&lt;/p&gt;

&lt;p&gt;To begin, let's assume that you have a branch called &lt;code&gt;feature-branch&lt;/code&gt; that is based on the &lt;code&gt;master&lt;/code&gt; branch. The &lt;code&gt;feature-branch&lt;/code&gt; contains three commits, &lt;code&gt;X&lt;/code&gt;, &lt;code&gt;Y&lt;/code&gt;, and &lt;code&gt;Z&lt;/code&gt;, as shown below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;          A - B - C - D &lt;span class="o"&gt;[&lt;/span&gt;master]
         /
    X - Y - Z &lt;span class="o"&gt;[&lt;/span&gt;feature-branch]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;Y&lt;/code&gt; commit in the feature-branch contains changes for both &lt;code&gt;fileA&lt;/code&gt; and &lt;code&gt;fileB&lt;/code&gt;. However, you want to split this commit into two separate commits, one for &lt;code&gt;fileA&lt;/code&gt; and one for &lt;code&gt;fileB&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using &lt;code&gt;git rebase -i&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;To do this, you need to start an interactive rebase using the &lt;code&gt;git rebase -i&lt;/code&gt; command. In this example, we will use the master branch as the base branch, so the command would be &lt;code&gt;git rebase -i master&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This will open an editor where you can specify the actions that you want to perform on each commit in the feature-branch. In this case, you want to split the &lt;code&gt;Y&lt;/code&gt; commit, so you need to replace the &lt;code&gt;pick&lt;/code&gt; command for commit &lt;code&gt;Y&lt;/code&gt; with the &lt;code&gt;edit&lt;/code&gt; command.&lt;/p&gt;

&lt;p&gt;Once you save and close the editor, the rebase will start and it will stop at the &lt;code&gt;Y&lt;/code&gt; commit. This will allow you to make changes to the &lt;code&gt;Y&lt;/code&gt; commit.&lt;/p&gt;

&lt;h2&gt;
  
  
  Split the Commit!
&lt;/h2&gt;

&lt;p&gt;To split the &lt;code&gt;Y&lt;/code&gt; commit, you first need to unstage the changes from the commit. This can be done using the &lt;code&gt;git reset HEAD~&lt;/code&gt; command. This will leave the changes in your working directory, but they will not be staged.&lt;/p&gt;

&lt;p&gt;Next, you can use the &lt;code&gt;git add&lt;/code&gt; command to stage only the changes for &lt;code&gt;fileA&lt;/code&gt;. Then, you can use the git commit command to create a new commit with the changes for &lt;code&gt;fileA&lt;/code&gt;. This will create a new commit, &lt;code&gt;Z&lt;/code&gt;, in the &lt;code&gt;feature-branch&lt;/code&gt;, as shown below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;          A - B - C - D &lt;span class="o"&gt;[&lt;/span&gt;master]
         /
    X - Y - Z &lt;span class="o"&gt;[&lt;/span&gt;feature-branch]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, you can use the &lt;code&gt;git add&lt;/code&gt; command to stage the remaining changes for &lt;code&gt;fileB&lt;/code&gt;. Then, you can use the &lt;code&gt;git commit&lt;/code&gt; command to create a new commit with the changes for &lt;code&gt;fileB&lt;/code&gt;. This will create a new commit, &lt;code&gt;W&lt;/code&gt;, in the &lt;code&gt;feature-branch&lt;/code&gt;, as shown below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;          A - B - C - D &lt;span class="o"&gt;[&lt;/span&gt;master]
         /
    X - Y - Z - W &lt;span class="o"&gt;[&lt;/span&gt;feature-branch]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Tada!
&lt;/h2&gt;

&lt;p&gt;Finally, you can use the &lt;code&gt;git rebase --continue&lt;/code&gt; command to continue the interactive rebase. This will apply the changes that you made to the &lt;code&gt;Y&lt;/code&gt; commit and create a new branch history with the two separate commits for &lt;code&gt;fileA&lt;/code&gt; and &lt;code&gt;fileB&lt;/code&gt; respectively!&lt;/p&gt;

&lt;p&gt;Now anytime you have a pesky lockfile change included with other files in a commit, you can separate it out, and then &lt;code&gt;drop&lt;/code&gt; them during your rebases to make interactive rebase efficient and clean!&lt;/p&gt;

</description>
      <category>git</category>
      <category>pnpm</category>
      <category>yarn</category>
      <category>javascript</category>
    </item>
    <item>
      <title>I maintain webpack, ask me anything!</title>
      <dc:creator>Sean Larkin</dc:creator>
      <pubDate>Wed, 11 Oct 2017 16:47:06 +0000</pubDate>
      <link>https://forem.com/thelarkinn/i-maintain-webpack-ask-me-anything-an8</link>
      <guid>https://forem.com/thelarkinn/i-maintain-webpack-ask-me-anything-an8</guid>
      <description>&lt;p&gt;I'm Sean,&lt;/p&gt;

&lt;p&gt;I maintain webpack.&lt;/p&gt;

&lt;p&gt;I work on Microsoft Edge DevTools. &lt;/p&gt;

&lt;p&gt;I love ðŸ”s.&lt;/p&gt;

&lt;p&gt;Ask.&lt;/p&gt;

&lt;p&gt;Me.&lt;/p&gt;

&lt;p&gt;Anything.&lt;/p&gt;

&lt;p&gt;:-D &lt;/p&gt;

</description>
      <category>ama</category>
      <category>webpack</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
