<?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: akorda</title>
    <description>The latest articles on DEV Community by akorda (@akorda).</description>
    <link>https://dev.to/akorda</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%2F565467%2Fa56ae34e-5cec-4566-8ea1-a157bac07637.png</url>
      <title>DEV Community: akorda</title>
      <link>https://dev.to/akorda</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/akorda"/>
    <language>en</language>
    <item>
      <title>Semi-linear git history</title>
      <dc:creator>akorda</dc:creator>
      <pubDate>Wed, 24 Nov 2021 08:21:02 +0000</pubDate>
      <link>https://dev.to/akorda/semi-linear-git-history-1191</link>
      <guid>https://dev.to/akorda/semi-linear-git-history-1191</guid>
      <description>&lt;p&gt;&lt;a href="https://www.reddit.com/r/programming/comments/od5mge/things_i_wish_git_had_commit_groups/"&gt;Tons of &lt;em&gt;e-ink&lt;/em&gt;&lt;/a&gt; has &lt;a href="https://www.bitsnbites.eu/git-history-work-log-vs-recipe/"&gt;been spilled all&lt;/a&gt; over &lt;a href="https://www.bitsnbites.eu/a-tidy-linear-git-history/"&gt;the internet&lt;/a&gt; about the &lt;em&gt;shape&lt;/em&gt; of git history.&lt;/p&gt;

&lt;p&gt;Personally, I want to be able to view the project history from a higher level &lt;strong&gt;but&lt;/strong&gt; I also want to view the implementation details of a feature.&lt;/p&gt;

&lt;p&gt;Typically viewing the higher level means that I want to see the history at the feature or bug-fix level. Additionally, I want to see when each feature made it to the main branch. I can view the history at this level by following only the first-parent commits of the log e.g. using the &lt;code&gt;--first-parent&lt;/code&gt; flag of the &lt;code&gt;git log&lt;/code&gt; command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git log &lt;span class="nt"&gt;--oneline&lt;/span&gt; &lt;span class="nt"&gt;--graph&lt;/span&gt; &lt;span class="nt"&gt;--first-parent&lt;/span&gt;
&lt;span class="k"&gt;*&lt;/span&gt; 663653a &lt;span class="o"&gt;(&lt;/span&gt;HEAD -&amp;gt; main, origin/main, origin/HEAD&lt;span class="o"&gt;)&lt;/span&gt; Feature 3
&lt;span class="k"&gt;*&lt;/span&gt; 6803a96 Feature 2
&lt;span class="k"&gt;*&lt;/span&gt; bdcdfa5 Feature 1
&lt;span class="k"&gt;*&lt;/span&gt; 2b6737e Initial commit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you are using the &lt;a href="https://marketplace.visualstudio.com/items?itemName=mhutchie.git-graph"&gt;Git Graph vscode extension&lt;/a&gt; you could activate this view by checking the &lt;code&gt;Only follow the first parent of commits&lt;/code&gt; option:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MVP8f2lx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/84orc042tfihjyv0aj2f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MVP8f2lx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/84orc042tfihjyv0aj2f.png" alt="First-parent commits only in git graph vscode extension settings" width="415" height="247"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The resulting view is the following:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WAcTznmg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a7n6himbqc2kza7rf1cv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WAcTznmg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a7n6himbqc2kza7rf1cv.png" alt="Following first-parent commits only" width="587" height="181"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But, if I want to see the implementation details of a feature I can omit the &lt;code&gt;--first-parent&lt;/code&gt; flag&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git log &lt;span class="nt"&gt;--oneline&lt;/span&gt; &lt;span class="nt"&gt;--graph&lt;/span&gt;
&lt;span class="k"&gt;*&lt;/span&gt; 663653a &lt;span class="o"&gt;(&lt;/span&gt;HEAD -&amp;gt; main, origin/main, origin/HEAD&lt;span class="o"&gt;)&lt;/span&gt; Feature 3
&lt;span class="k"&gt;*&lt;/span&gt;   6803a96 Feature 2
|&lt;span class="se"&gt;\&lt;/span&gt;
| &lt;span class="k"&gt;*&lt;/span&gt; 1189f63 Call hw 5
| &lt;span class="k"&gt;*&lt;/span&gt; 1f33ff3 Call hw 4
|/
&lt;span class="k"&gt;*&lt;/span&gt;   bdcdfa5 Feature 1
|&lt;span class="se"&gt;\&lt;/span&gt;
| &lt;span class="k"&gt;*&lt;/span&gt; 7f48316 Call 2 more &lt;span class="nb"&gt;times&lt;/span&gt;
| &lt;span class="k"&gt;*&lt;/span&gt; 9674fd6 Add console application
|/
&lt;span class="k"&gt;*&lt;/span&gt; 2b6737e Initial commit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The corresponding Git Graph view is:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2p4yh2D9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fbv9brcc05htz4yxaflh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2p4yh2D9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fbv9brcc05htz4yxaflh.png" alt="All commits" width="584" height="274"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If the tool that you are using does not support semi-linear merges you could do it manually. Please keep in mind that there is no way to guarantee that the merge will produce a semi-linear result: someone else could have pushed changes to the main branch! Use the &lt;code&gt;-no-ff&lt;/code&gt; flag to force the creation of a merge commit &lt;a href="https://git-scm.com/docs/git-merge"&gt;in all cases, even when the merge could instead be resolved as a fast-forward&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;My current git workflow is the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# pull the latest changes of the main branch&lt;/span&gt;
git pull
&lt;span class="c"&gt;# create a feature/topic branch before starting new work&lt;/span&gt;
git switch &lt;span class="nt"&gt;-c&lt;/span&gt; feature-branch
&lt;span class="c"&gt;# make some changes and commit often in the topic branch&lt;/span&gt;
git add &lt;span class="nb"&gt;.&lt;/span&gt;
git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Add a comment about this commit"&lt;/span&gt;
&lt;span class="c"&gt;# periodically rebase your work onto main branch&lt;/span&gt;
git fetch origin
git rebase origin/main
&lt;span class="c"&gt;# make more changes&lt;/span&gt;
git add &lt;span class="nb"&gt;.&lt;/span&gt;
git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Add a comment about the new changes"&lt;/span&gt;
&lt;span class="c"&gt;# switch to main branch and merge the topic branch using the `--no-ff` flag&lt;/span&gt;
&lt;span class="c"&gt;# don't forget to set the message of the merge commit using the `-m` flag&lt;/span&gt;
git switch main
git pull
git merge &lt;span class="nt"&gt;--no-ff&lt;/span&gt; &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Add feature 5"&lt;/span&gt; feature-branch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  See also
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://stackoverflow.com/questions/59714347/semi-linear-merge"&gt;Semi-linear-merge discussion&lt;/a&gt; in Stack Overflow (see several answers).&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://devblogs.microsoft.com/devops/pull-requests-with-rebase/#semi-linear-merge"&gt;Semi-linear merge&lt;/a&gt; in Azure devops&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://confluence.atlassian.com/bitbucketserver/pull-request-merge-strategies-844499235.html"&gt;Rebase, merge&lt;/a&gt; in BitBucket&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.gitlab.com/ee/user/project/merge_requests/reviews/#semi-linear-history-merge-requests"&gt;Semi-linear merge&lt;/a&gt; in BitBucket&lt;/li&gt;
&lt;li&gt;I'm not sure if &lt;a href="https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/configuring-pull-request-merges/about-merge-methods-on-github"&gt;GitHub supports semi-linear&lt;/a&gt; merges&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Happy coding \m/&lt;/p&gt;

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