<?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: Evgeniy Shteiner</title>
    <description>The latest articles on DEV Community by Evgeniy Shteiner (@rasenkod).</description>
    <link>https://dev.to/rasenkod</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%2F476543%2F56a3a766-8764-4ce4-acc9-20ce131ae6e7.png</url>
      <title>DEV Community: Evgeniy Shteiner</title>
      <link>https://dev.to/rasenkod</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rasenkod"/>
    <language>en</language>
    <item>
      <title>Git Flow and why it is important to maintain history correctly</title>
      <dc:creator>Evgeniy Shteiner</dc:creator>
      <pubDate>Mon, 28 Sep 2020 13:07:38 +0000</pubDate>
      <link>https://dev.to/rasenkod/git-flow-and-why-it-is-important-to-maintain-history-correctly-3ndb</link>
      <guid>https://dev.to/rasenkod/git-flow-and-why-it-is-important-to-maintain-history-correctly-3ndb</guid>
      <description>&lt;p&gt;Hello, in this article I will speak about reasons why it is important to maintain a history, as well as we will consider one of the ways to do it. This is my first article and I was inspired to write it at &lt;a href="https://appus.software/" rel="noopener noreferrer"&gt;Appus Studio&lt;/a&gt;, where we also discuss how to work with git and choose the best approach for each project.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F6l8p92eh4fs48rpkhdlr.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F6l8p92eh4fs48rpkhdlr.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When maintaining your history, try to follow these 2 rules:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Master branch should contain only logically completed commits, for example, task A is done or bug B is fixed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;History should not be branchy and confusing with numerous merge commits. In other words, it's better to use rebase instead of merge.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The history of a discrete form, when each commit is logically completed, allows you to work faster and solve problems in the future. For example, you need to do an identical task to task "A" after a while, or you find out that after adding this task, something works incorrectly. You can easily view all the changed files in one commit or checkout to this commit to test if this logic is not in the project anymore or if it has been changed. Also in git, there is a mode to help you search for bugs with git bisect. It helps a developer find a commit in a given range where the bug appeared. If you have a lot of intermediate commits, or worse, if your commits include not compiled code, it is very difficult to use and your development process will be at least 20% slower.&lt;/p&gt;

&lt;p&gt;Rebasing instead of merging is better, and let me illustrate it. For instance, I work in the dev branch, for a certain period and I have done 3 tasks (f1, f2, f3), and my colleague Alex has also done 3 (c1, c2, c3).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fsmb8ou7tr8uv2tp1hl6g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fsmb8ou7tr8uv2tp1hl6g.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And then it becomes necessary to put all our changes together and we decide to use merging. If we merge my branches into dev and then do it with Alex’s branches, this is what we get:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fvzcqpq4odylgw2ofdvzf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fvzcqpq4odylgw2ofdvzf.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Above is the result of only two of the developers committing, so it’s hard to imagine what happens when 3-4 people work on the project and each does several commits in each branch. Obviously, in this case, your history will be even more confusing.&lt;/p&gt;

&lt;p&gt;If you use rebase and add up all the branches one by one, you obtain the following result:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F9apy4fo2fx9oq9fomapi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F9apy4fo2fx9oq9fomapi.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But it only is convenient if you rebase a branch with just 1-2 commits, or if you know that you will not have a lot of conflicts with the code that is already in dev. Since the rebase applies commit one by one, the following scenario is possible: you resolve conflicts in one of the first commits, and then in the following commits you have conflicts with the same files that you worked with and as a result, you resolve conflicts with your own code, which is extremely inconvenient and time-consuming. You probably thought that in this case, it is better to use merge after all. The question is controversial and depends on what kind of commits there are in your branch. If they are big and you worked on each of them for about a week, then yes, but if they all relate to some task, then it is better to squash commits by making one commit from this branch, and then rebase this commit to dev.&lt;/p&gt;

&lt;p&gt;The question is, what the best choice is, to amend or to reset your commit and only then upload the task to dev with 1-2 commits, or make a lot of commits, and then squash.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffokzbq0qif005tg6gbpj.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffokzbq0qif005tg6gbpj.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It depends on your choice and on the requirements of the project. The fact is that your team lead or customer can ask for daily commits, even if the code is unstable, in order to monitor your progress. In this case, you have no choice but to do squash.&lt;/p&gt;

&lt;p&gt;To illustrate, I will create a branch f4 and make 4 daily commits in it from where we started, create a temp branch f4_temp, it will replace the remote origin/f4 for me that I would have created if I worked with a remote repository.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffohcw4pf532ms5frg8ju.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffohcw4pf532ms5frg8ju.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And then squash the commits and rebase.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F08h23hw21kmzw0naxdas.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F08h23hw21kmzw0naxdas.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now the f4 branch has the same changes as in f4_temp, if you go to the commit settings, you can see that the comments are also saved.&lt;br&gt;
But what if you want to split a task into multiple commits? For example, if you have made internal logic that relates to your task, you want it to be in a separate commit, but it is not yet ready to be uploaded to dev, because you need to finish the UI as well. For example, the f4 branch is internal logic, and as you can see, I have not yet uploaded it into dev, we repeat everything according to the same principle, create the f4_ui branch, and make 3 commits.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fbrud0h2w5kzua9ax4tqn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fbrud0h2w5kzua9ax4tqn.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we squash, upload it to dev, and also keep the f4_ui_temp (origin) branch for the team lead, it can always be removed later.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F2zqjtha1yyc3yuyq972h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F2zqjtha1yyc3yuyq972h.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As a result, we figured out why it is important to maintain the history and how to do it correctly. Thank you for reading, if you have any questions or suggestions, please contact me personally or the company I work at - &lt;a href="https://appus.software/" rel="noopener noreferrer"&gt;Appus Studio&lt;/a&gt;, helping you will be a pleasure.&lt;/p&gt;

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