<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ayush Poddar on Medium]]></title>
        <description><![CDATA[Stories by Ayush Poddar on Medium]]></description>
        <link>https://medium.com/@ayushpoddar?source=rss-7c284d9e368e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*nDHJaq699dPTM_Tw2PW8yw.jpeg</url>
            <title>Stories by Ayush Poddar on Medium</title>
            <link>https://medium.com/@ayushpoddar?source=rss-7c284d9e368e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 19:19:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ayushpoddar/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Practically evaluate your system’s performance — Look beyond time complexity]]></title>
            <link>https://ayushpoddar.medium.com/practically-evaluate-your-systems-performance-look-beyond-time-complexity-d13613970af4?source=rss-7c284d9e368e------2</link>
            <guid isPermaLink="false">https://medium.com/p/d13613970af4</guid>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[benchmark]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[time-complexity]]></category>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Ayush Poddar]]></dc:creator>
            <pubDate>Fri, 10 May 2024 06:01:01 GMT</pubDate>
            <atom:updated>2024-05-10T06:13:12.040Z</atom:updated>
            <content:encoded><![CDATA[<h3>Practically evaluate your system’s performance — Look beyond time complexity</h3><p><a href="https://en.wikipedia.org/wiki/Time_complexity">Time complexity</a> is a common parameter used to describe the performance of an algorithm. They tell us about the performance of an algorithm in terms of the size of the input. In other words, time complexity is a measure of the affect of input size on performance.</p><blockquote><em>Consider an algorithm such as linear search on an unordered list of numbers </em>(linear time complexity)<em>. The time taken by this algorithm increases linearly with the size of the input.</em></blockquote><p>Time complexity is useful for a theoretical analysis on the performance of an algorithm. However, in the real world, our programs run on many layers of abstraction which introduce their own complexities and optimisations that are hard to account for in terms of mathematical equations or theoretical concepts.</p><p>Real world data have special constraints which, in combination with the above-mentioned complexities and optimisations, may result in a theoretical worse algorithm to perform better. Apart from this, practically, we are often happy with good enough solutions that works for 99% of the cases in the real world. Many systems are built such that their accuracy is traded-off in favour of a performance boost.</p><blockquote><strong>Example</strong>: Most modern CPUs optimise the performance of our programs by pre-calculating the results of the operations that are yet to be executed in our coding programs. However, when these programs utilise conditionals <em>(like if-else statements)</em>, there are chances of the pre-calculations occurring on the incorrect branch. This leads to a wastage of CPU cycles as the pre-calculations are performed on the wrong branch, affecting our systems’ performance.</blockquote><p>The aim of this post is to encourage you to think beyond the time complexity calculations when evaluating your systems’ performance, and corroborate your knowledge of time complexity by benchmarking with real world data in the real world-like environment.</p><h3>Demonstration</h3><p>Consider this common leetcode problem: <a href="https://leetcode.com/problems/climbing-stairs/description/">Climbing Stairs</a>. The problem statement goes something like this:</p><blockquote><em>There are </em><em>n steps in a staircase. You can take either 1, 2, or 3 steps at a time. In how many distinct ways can you climb the stairs?¹</em></blockquote><p>The solution to this problem is straight-forward. The aim of this post is not to discuss the correct solution but rather discuss the importance of evaluating the solution beyond the asymptotic analysis, i.e., the time and space complexity. The best solution to this problem has a linear time complexity and a constant space complexity. But I will be analysing the approach where the time complexity is in the order of O(2^n), since it will best demonstrate the importance of benchmarking by comparing similar algorithms with similar time complexity.</p><h3>Building the solution(s)</h3><p>As an example consider a staircase with 5 steps (n = 5).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*_DmGl-mZPfxQFsuG.png" /><figcaption><em>“Stairing” into the abyss</em></figcaption></figure><p>From the initial position, you can either go to <strong>step 1</strong> or <strong>step 2</strong> or <strong>step 3</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*7BqBT7J7xrUcrEr4.png" /><figcaption><em>The first step (or leap)</em></figcaption></figure><p>Essentially, now the problems breaks down into the sum of three sub-problems:</p><ol><li>Number of ways you can get to <strong>step 5</strong> from <strong>step 1</strong>. <em>Or</em>, the number of ways you can climb a 4-step staircase (n = 4).</li><li>Number of ways you can get to <strong>step 5</strong> from <strong>step 2</strong>. <em>Or</em>, the number of ways you can climb a 3-step staircase (n = 3).</li><li>Number of ways you can get to <strong>step 5</strong> from <strong>step 3</strong>. <em>Or</em>, the number of ways you can climb a 2-step staircase (n = 2).</li></ol><p>Mathematically speaking, if the function 𝑓(𝑛) is defined as the number of ways you can climb a staircase of 𝑛 steps, then:</p><pre>f(n) = f(n - 1) + f(n - 2) + f(n - 3)</pre><p>A straight-forward code implementation for the same is:</p><pre>def recursiveSolution(n):<br>    if n &lt;= 2:<br>        # When n = 0, 1, 2; return 1, 1, 2 respectively.<br>        # You can climb a 0 or 1 step staircase in only one way<br>        # and climb a 2-step staircase in 2 ways ((1, 1) and (2))<br>        return (1, 1, 2)[n]<br>    return recursiveSolution(n - 1) + recursiveSolution(n - 2) + recursiveSolution(n - 3)</pre><h4>Tree based approach</h4><p>Another way that this problem can be approached is by thinking in terms of a tree, where each node of the tree represents your current position on the staircase. There are three possible children from each node, one of every step you can take from your current position.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*XOfEujiAdKyKVnyo.png" /><figcaption>The tree representation <a href="https://d32g573a6sduc5.cloudfront.net/images/2ivc7gxas8ngb9sd.png">(Download)</a></figcaption></figure><p>Next, you can find all the possible paths to the desired node ( position). Each node ( position) can be represented by a number, which represents your current position on the staircase. Initially, you start with position = 0 and you need to find all possible paths to position = n ( position = 5 in this case).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/516/0*CwyABBt5dbxfe7QH.png" /><figcaption>Tree. Nodes represented as number</figcaption></figure><p>This turns into a classic graph/tree problem, which you can solve either by performing a breadth-first search (BFS) or depth-first search (DFS). Implementing a depth-first search would basically replicate the recursive solution implemented earlier, with the only difference being that you would be manually managing the stack, instead of the program managing the stack in the form of call stack. The python implementation of a DFS solution would be:</p><pre>from collections import deque<br><br>def graphDFS(n):<br>    stack = deque()<br>    stack.append(0)  # start with position = 0<br>    count = 0<br>    while stack:<br>        x = stack.pop()  # get next position to evaluate<br>        if n - x &lt;= 2:  # if current position is 0 or 1 or 2<br>            count += (1, 1, 2)[n - x]  # just add to count<br>            continue  # further evaluation not needed<br>        # Append the children to the stack<br>        stack.append(x + 1)<br>        stack.append(x + 2)<br>        stack.append(x + 3)<br>    return count</pre><p>The core logic of the recursiveSolution function has been replicated as-it-is to ensure that both functions are as equivalent as possible. The breadth-first version of the solution would be:</p><pre>from collections import deque<br><br>def graphBFS(n):<br>    count = 0<br>    queue = deque()<br>    queue.append(0)  # start with position = 0<br>    while queue:<br>        x = queue.popleft()  # get next position to evaluate<br>        if n - x &lt;= 2:  # if current position is 0 or 1 or 2<br>            count += (1, 1, 2)[n - x]  # just add to count<br>            continue  # further evaluation not needed<br>        # Push the children to the queue<br>        queue.append(x + 1)<br>        queue.append(x + 2)<br>        queue.append(x + 3)<br>    return count</pre><p>The two functions are the same except for the usage of stack in one and queue on another. The time complexity of all the three functions is O(2^n).</p><blockquote>This post assumes that you know how to calculate time complexity. Hence, it does not cover the calculation of the time complexity.</blockquote><h3>Performance analysis</h3><p>To benchmark the performance of each of the above functions, I wrote a script that called each function from n = 1 to n = 20 and repeated this x times (called runs). Essentially, I wanted to find the total time taken by a function if it is called for all values between n = 1 and n = 20. The script looks like this:</p><pre>import time<br><br># Helper function to measure runtime<br>def measure_runtime(func, n):<br>    start_time = time.perf_counter()<br>    result = func(n)<br>    end_time = time.perf_counter()<br>    return end_time - start_time, result<br><br><br>function_timings = {}<br>functions = [recursiveSolution, graphBFS, graphDFS]<br>times = [0 for _ in functions]  # to store the running times corresponding to each function<br>runs = 10000  # number of times to repeat the benchmarking =&gt; 10, 100, 1000, 10000<br><br>for _ in range(runs):<br>    for n in range(20):  # Test for n = 1 to n = 20<br>        for i in range(len(functions)):<br>            func = functions[i]<br>            time_taken, _ = measure_runtime(func, n)<br>            times[i] += time_taken<br><br>for i in range(len(functions)):<br>    func = functions[i]<br>    # Average running time per run<br>    function_timings[func.__name__] = times[i] / runs</pre><p>The results shown below is the average execution time per “run”. In other words, each bar shows the total execution time for a function for all values of n from 1 to 20.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*v0UHhoFFQvoG1ccK.png" /></figure><p>As can be seen, clearly the recursiveSolution function is the fastest. The next fastest function is the graphBFS function, which is approximately <strong>~40%</strong> slower than recursiveSolution function.</p><blockquote>I found it intriguing that graphDFS is the slowest one (even if by a small margin). graphDFS is fundamentally closer to recursiveSolution since both of them use a stack to gather the results.</blockquote><h3>Thoughts</h3><p>All the three functions have the same time complexity. All of them essentially implement the same logic. All of them return/continue when number of steps left is less than or equal to 2 (&lt;= 2). Yet, there is a <strong>~40%</strong> difference in their performances.</p><p>The analysis above aptly demonstrates that equivalent time complexity or algorithmic logic does not necessarily imply equivalent system performance. It is necessary to benchmark the functions/systems we implement to be able to accurately comment on their performance.</p><p>However, it would be impractical to benchmark every bit of code we write. The decision on whether or not to benchmark is a judgement call that improves as we learn more about the hidden layers of abstraction in our systems. With knowledge and experience, we can make better judgement on whether or not we use time complexity as the sole metric to gauge the performance of our systems. <em>For example, in almost all cases, binary search would be better than linear search on a sorted list of numbers</em>.</p><h3>Bonus: Best solution to this problem</h3><p>The solution to the <a href="https://leetcode.com/problems/climbing-stairs/description/">Climbing Stairs</a> problem that runs in linear time complexity is:</p><pre>def linear(n):<br>    a, b, c = 1, 1, 2<br>    for _ in range(n):<br>        a, b, c = b, c, a + b + c<br>    return a</pre><blockquote>The solution is similar to the solution for getting the <em>nth</em> number in the Fibonacci sequence.</blockquote><p>I encourage you to try out different solutions (all of which execute in linear time complexity) and compare their performances. You can compare the above function with this one:</p><pre>def linear2(n):<br>    if n == 1:<br>        return 1<br>    dp = [0 for _ in range(n + 1)]<br>    dp[1] = 1<br>    dp[2] = 2<br>    for i in range(3, n + 1):<br>        dp[i] = dp[i - 1] + dp[i - 2] + dp[i - 3]<br>    return dp[n]</pre><p>Think about more ways to achieve the same result in linear time complexity and compare their performances.</p><h3>References</h3><ol><li><a href="https://csprimer.com/watch/staircase/">CS Primer — Staircase ascent problem</a> → <em>I recommended this course for experienced software engineers who are looking to learn more about the foundational computer science concepts</em>.</li><li><a href="https://csprimer.com/watch/analysis-practice/">CS Primer — Seminar on analysing systems</a></li></ol><h3>Footnotes</h3><p>[1]: Leetcode presents a variant of this problem where you can take only 1 or 2 steps at a time.</p><p><em>Originally published at </em><a href="https://poddarayush.com/posts/beyond-time-complexity/"><em>https://poddarayush.com</em></a><em> on May 10, 2024.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d13613970af4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduce checkpoints in your code — Learn how to use tagging in Git]]></title>
            <link>https://ayushpoddar.medium.com/introduce-checkpoints-in-your-code-learn-how-to-use-tagging-in-git-602be6b02b9b?source=rss-7c284d9e368e------2</link>
            <guid isPermaLink="false">https://medium.com/p/602be6b02b9b</guid>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Ayush Poddar]]></dc:creator>
            <pubDate>Tue, 15 Aug 2023 07:38:55 GMT</pubDate>
            <atom:updated>2023-08-15T08:56:51.403Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduce checkpoints in your code — Learn how to use tagging in Git</h3><p>Tags in Git can be likened to checkpoints of a game. You can tag points in a repository’s history that are important to you. Typically, tags are used to mark release versions like v1.0.0, v2.0.0, etc.</p><p>Tags are associated with a specific commit in your repository. In other words, after you create a commit, you can tag that commit with any name of you liking — e.g., v1.0.0, v2.0.0, etc.</p><p>In this post, I am going to tell you about the two types of tags in Git and how to create them.</p><h3>Types of tags</h3><p>There are two types of tags in Git:</p><ol><li>Lightweight</li><li>Annotated</li></ol><h4>Lightweight tags</h4><p>These tags are simply pointers to a commit. You can think of them as “bookmarks” to a commit. They cannot store any metadata apart from the name of the tag itself. As a best practice, these tags are generally used for temporary bookmarking and private use.</p><p>The command to create a lightweight tag is:</p><pre>git tag &lt;tagname&gt;</pre><p>where tagname can be anything that you want.</p><h4>Annotated tags</h4><p>Annotated tags are stored as independent objects in the Git database, with its own SHA1 hash, and metadata. They are capable of storing metadata such as author of the tag, email of the tagger, date of tagging and a message describing the tag. The command to create an annotated tag is:</p><pre>git tag -a &lt;tagname&gt; -m &lt;message&gt;<br><br># Example<br>git tag -a v1.0.0 -m &quot;App is open to the public now&quot;</pre><p>If you provide a message using the -m flag, then you don&#39;t even need to provide the -a flag. You can just do: git tag &lt;tagname&gt; -m &lt;message&gt;</p><p>Annotated tags are useful when you want to push the tag to the public domain. They are useful because they can hold metadata like tagger’s name and date of tagging. This information can help, for example, when trying to track the root cause of a bug.</p><h3>Can a tag only point to the latest commit?</h3><p>No. You can also create a tag that points to a previous commit. Consider the following git log:</p><pre>305e248 - Ayush Poddar, 10 weeks ago : refactor: split into two methods<br>6f7f4ab - Ayush Poddar, 10 weeks ago : modify the instance doubles ensuring green specs<br>fe59bb7 - Ayush Poddar, 10 weeks ago : add logic to show different color for hidden files/directories<br>4f1333f - Ayush Poddar, 10 weeks ago : add colors for hidden files/directories<br>1e1f10c - Ayush Poddar, 10 weeks ago : modify indentations<br>28c188b - Claudio Bley, 3 months ago : Merge pull request #594 from ayushpoddar/show-abs-path-xargs<br>44c370b - Ayush Poddar, 3 months ago : Revert &quot;version bump&quot;</pre><p>What if we want to create a tag that points to commit 1e1f10c (modify indentations)? You can simply add the commit hash ( 1e1f10c) at the end of the git tag command. So the command would look like this:</p><pre># Lightweight tag<br>git tag &lt;tagname&gt; 1e1f10c<br><br># Annotated tag<br>git tag -a &lt;tagname&gt; -m &lt;tag message&gt; 1e1f10c</pre><h3>Viewing details of a tag</h3><p>To view details of a tag, you can use the git show command. The command is:</p><pre>git show &lt;tagname&gt;</pre><p>The output differs slightly for lightweight and annotated tags. In case of lightweight tags, only the associated commit’s information is displayed. The sample output is shown below.</p><pre>commit 305e2486f4431fc7e0487423f90ed380852194b2<br>Author: Ayush Poddar &lt;ayush.mail.id@gmail.com&gt;<br>Date:   Wed Jun 7 18:00:34 2023 +0530<br><br>    refactor: split into two methods<br><br>diff --git a/lib/colorls/core.rb b/lib/colorls/core.rb<br>index b558968..f5f7707 100644<br>--- a/lib/colorls/core.rb<br>+++ b/lib/colorls/core.rb<br>@@ -416,20 +416,32 @@ module ColorLS<br> <br>     def options(content)<br>       if content.directory?<br>-        key = content.name.downcase.to_sym<br>-        key = @folder_aliases[key] unless @folders.key? key<br>-        key = :folder if key.nil?<br>-        color = content.hidden? ? @colors[:hidden_dir] : @colors[:dir]<br>-        group = :folders<br>+        options_directory(content).values_at(:key, :color, :group)<br>       else<br>-        key = File.extname(content.name).delete_prefix(&#39;.&#39;).downcase.to_sym<br>-        key = @file_aliases[key] unless @files.key? key<br>-        color = file_color(content, key)<br>-        group = @files.key?(key) ? :recognized_files : :unrecognized_files<br>-        key = :file if key.nil?<br>+        options_file(content).values_at(:key, :color, :group)<br>       end<br>+    end<br>+<br>+    def options_directory(content)<br>+      key = content.name.downcase.to_sym<br>+      key = @folder_aliases[key] unless @folders.key?(key)<br>+      key = :folder if key.nil?<br>+<br>+      color = content.hidden? ? @colors[:hidden_dir] : @colors[:dir]<br>+<br>+      {key: key, color: color, group: :folders}<br>+    end<br>+<br>+    def options_file(content)<br>+      key = File.extname(content.name).delete_prefix(&#39;.&#39;).downcase.to_sym<br>+      key = @file_aliases[key] unless @files.key?(key)<br>+<br>+      color = file_color(content, key)<br>+      group = @files.key?(key) ? :recognized_files : :unrecognized_files<br>+<br>+      key = :file if key.nil?<br> <br>-      [key, color, group]<br>+      {key: key, color: color, group: group}<br>     end<br> <br>     def tree_contents(path)</pre><p>In case of annotated tags, additional metadata such as tagger name, tagging date, etc. are also displayed. A sample output is given below. Notice the metadata displayed above the commit information.</p><pre>tag annotated-tag<br>Tagger: Ayush Poddar &lt;ayush.mail.id@gmail.com&gt;<br>Date:   Tue Aug 15 13:38:36 2023 +0530<br><br>This is the sample tag<br><br>commit 305e2486f4431fc7e0487423f90ed380852194b2<br>Author: Ayush Poddar &lt;ayush.mail.id@gmail.com&gt;<br>Date:   Wed Jun 7 18:00:34 2023 +0530<br><br>    refactor: split into two methods<br><br>diff --git a/lib/colorls/core.rb b/lib/colorls/core.rb<br>index b558968..f5f7707 100644<br>--- a/lib/colorls/core.rb<br>+++ b/lib/colorls/core.rb<br>@@ -416,20 +416,32 @@ module ColorLS<br> <br>     def options(content)<br>       if content.directory?<br>-        key = content.name.downcase.to_sym<br>-        key = @folder_aliases[key] unless @folders.key? key<br>-        key = :folder if key.nil?<br>-        color = content.hidden? ? @colors[:hidden_dir] : @colors[:dir]<br>-        group = :folders<br>+        options_directory(content).values_at(:key, :color, :group)<br>       else<br>-        key = File.extname(content.name).delete_prefix(&#39;.&#39;).downcase.to_sym<br>-        key = @file_aliases[key] unless @files.key? key<br>-        color = file_color(content, key)<br>-        group = @files.key?(key) ? :recognized_files : :unrecognized_files<br>-        key = :file if key.nil?<br>+        options_file(content).values_at(:key, :color, :group)<br>       end<br>+    end<br>+<br>+    def options_directory(content)<br>+      key = content.name.downcase.to_sym<br>+      key = @folder_aliases[key] unless @folders.key?(key)<br>+      key = :folder if key.nil?<br>+<br>+      color = content.hidden? ? @colors[:hidden_dir] : @colors[:dir]<br>+<br>+      {key: key, color: color, group: :folders}<br>+    end<br>+<br>+    def options_file(content)<br>+      key = File.extname(content.name).delete_prefix(&#39;.&#39;).downcase.to_sym<br>+      key = @file_aliases[key] unless @files.key?(key)<br>+<br>+      color = file_color(content, key)<br>+      group = @files.key?(key) ? :recognized_files : :unrecognized_files<br>+<br>+      key = :file if key.nil?<br> <br>-      [key, color, group]<br>+      {key: key, color: color, group: group}<br>     end<br> <br>     def tree_contents(path)</pre><h3>Listing tags</h3><p>To list all tags in a repository, you can use the git tag command <em>(without any arguments)</em>. You can also supply the--list (-l) flag which takes an optional argument.</p><p>Using git tag --list, as it is, will also list all the tags just like git tag would. The sample output of running git tag --list or git tag is shown below.</p><pre>v1.0.0<br>v1.0.1<br>v1.0.2<br>v1.0.3<br>v1.0.4<br>v1.0.5<br>v1.0.7<br>v1.0.8<br>v1.0.9<br>v1.1.0<br>v1.1.1<br>v1.2.0<br>v1.3.0<br>v1.3.1<br>v1.3.2<br>v1.3.3<br>v1.4.0<br>v1.4.1<br>v1.4.2<br>v1.4.3<br>v1.4.4<br>v1.4.5<br>v1.4.6</pre><h4>How to filter the tags by their name?</h4><p>You can provide an argument to the --list flag to filter the tags. The argument needs to be the pattern that you want to filter by. The pattern can be the exact string to match or a <a href="https://linuxhint.com/bash_wildcard_tutorial/">shell wildcard</a>. For example, if we want to view only those tags which start with &quot;v1.0&quot;, we can do:</p><pre>$ git tag --list &#39;v1.0.*&#39;<br><br># Output<br>v1.0.0<br>v1.0.1<br>v1.0.2<br>v1.0.3<br>v1.0.4<br>v1.0.5<br>v1.0.7<br>v1.0.8<br>v1.0.9</pre><h4>How to filter for multiple patterns?</h4><p>The --list flag can also take multiple arguments. In such a case, all tags which match <strong>any</strong> of the provided patterns will be listed. For example, if we want to list all tags which start with &quot;v1.0&quot;, along with the tags which start with &quot;v1.4&quot; we can do:</p><pre>$ git tag --list &#39;v1.0.*&#39; &#39;v1.4.*&#39;<br><br># Output<br>v1.0.0<br>v1.0.1<br>v1.0.2<br>v1.0.3<br>v1.0.4<br>v1.0.5<br>v1.0.7<br>v1.0.8<br>v1.0.9<br>v1.4.0<br>v1.4.1<br>v1.4.2<br>v1.4.3<br>v1.4.4<br>v1.4.5<br>v1.4.6</pre><h3>Conclusion</h3><p>In this post, you learned about Git tags and the different types of tags supported by it. You also learned:</p><ul><li>how to create tags</li><li>view details of a specific tag</li><li>List all the tags and filter them by their name</li></ul><h3>References</h3><ul><li><a href="https://stackoverflow.com/a/4971817/6212985">This stackoverflow answer</a></li><li><a href="https://www.atlassian.com/git/tutorials/inspecting-a-repository/git-tag#:~:text=Annotated%20tags%20store%20extra%20meta,quick%20links%20to%20relevant%20commits.">https://www.atlassian.com/git/tutorials/inspecting-a-repository/git-tag</a></li><li><a href="https://git-scm.com/book/en/v2/Git-Basics-Tagging">https://git-scm.com/book/en/v2/Git-Basics-Tagging</a></li><li><a href="https://git-scm.com/docs/git-tag">https://git-scm.com/docs/git-tag</a></li></ul><p><em>Originally published at </em><a href="https://poddarayush.com/posts/git-tags/"><em>https://poddarayush.com</em></a><em> on August 15, 2023.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=602be6b02b9b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Git Remotes for Beginners: Inspect, Rename and Remove]]></title>
            <link>https://ayushpoddar.medium.com/git-remotes-for-beginners-inspect-rename-and-remove-4767a5a47596?source=rss-7c284d9e368e------2</link>
            <guid isPermaLink="false">https://medium.com/p/4767a5a47596</guid>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Ayush Poddar]]></dc:creator>
            <pubDate>Mon, 14 Aug 2023 06:28:02 GMT</pubDate>
            <atom:updated>2023-08-14T07:23:13.527Z</atom:updated>
            <content:encoded><![CDATA[<p>In the <a href="https://poddarayush.com/posts/git-remote-commands/">previous post, I introduced you to the concept of Git remotes</a>. I showed you that a Git repository can have more than one remote and how you can fetch data from a particular remote.</p><p>In this post, I am about to answer the following questions:</p><ol><li>How do you view more details about a particular remote? The branches present in the remote, and how those branches map to your local branches.</li><li>How do you rename a remote?</li><li>How do you stop tracking (remove) a remote from your Git repository?</li></ol><h3>View (Inspect) a Git remote</h3><p>The command to achieve this is: git remote show &lt;shortname&gt;. For example, the sample output of running git remote show origin is shown below.</p><pre>* remote origin<br>  Fetch URL: git@github.com:ayushpoddar/colorls.git<br>  Push  URL: git@github.com:ayushpoddar/colorls.git<br>  HEAD branch: main<br>  Remote branches:<br>    color-hidden-files  tracked<br>    main                tracked<br>    show-abs-path-xargs tracked<br>    size-in-bytes       tracked<br>  Local branches configured for &#39;git pull&#39;:<br>    color-hidden-files  merges with remote color-hidden-files<br>    main                merges with remote main<br>    show-abs-path-xargs merges with remote show-abs-path-xargs<br>    size-in-bytes       merges with remote size-in-bytes<br>  Local refs configured for &#39;git push&#39;:<br>    color-hidden-files  pushes to color-hidden-files  (up to date)<br>    main                pushes to main                (up to date)<br>    show-abs-path-xargs pushes to show-abs-path-xargs (up to date)<br>    size-in-bytes       pushes to size-in-bytes       (up to date)</pre><p>I want you make the following observations:</p><ul><li>This command outputs the full URL of the remote that the shortname is mapped to.</li><li>The list of branches in remote have been “fetched” to your local repository.</li><li>It lists the mapping between your local branches and remote branches. This helps you with knowing the remote branch that will be used when running git pull or git push on a local branch.</li></ul><blockquote>If you are wondering if the branch names in remote and the corresponding branch names in local can be different, I would encourage you to read <a href="https://docs.github.com/en/get-started/using-git/pushing-commits-to-a-remote-repository#renaming-branches">this Github article</a>.</blockquote><h3>How to rename a remote shortname?</h3><p>Simple command.</p><pre>git remote rename &lt;old-shortname&gt; &lt;new-shortname&gt;</pre><h3>How to remove a remote?</h3><p>If you want to stop tracking a remote, you need to remove all references to the remote from your local repository. The command to do so is:</p><pre>git remote remove &lt;shortname&gt;<br><br># rm is an alias for remove<br>git remote rm &lt;shortname&gt;</pre><h3>Final words</h3><p>After reading the <a href="https://poddarayush.com/posts/git-remote-commands/">first post</a> and this post, you are equipped enough to understand any advanced ideas or commands that you may encounter. You can explore more on your own using man git-remote or git help remote.</p><h3>References</h3><ul><li><a href="https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes">https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes</a></li></ul><p><em>Originally published at </em><a href="https://poddarayush.com/posts/git-remote-part-2/"><em>https://poddarayush.com</em></a><em> on August 14, 2023.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4767a5a47596" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Git Remotes for Beginners: An Introductory Guide]]></title>
            <link>https://ayushpoddar.medium.com/git-remotes-for-beginners-an-introductory-guide-8c73284565ae?source=rss-7c284d9e368e------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c73284565ae</guid>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Ayush Poddar]]></dc:creator>
            <pubDate>Sun, 13 Aug 2023 05:55:41 GMT</pubDate>
            <atom:updated>2023-08-13T12:40:15.840Z</atom:updated>
            <content:encoded><![CDATA[<p>If you have read my post on <a href="https://poddarayush.com/posts/history-of-git/">the history of Git</a>, you would know that in order to have effective collaboration, we need to have a <a href="https://poddarayush.com/shorts/git-storage-of-versions/">version database</a> that is accessible to everyone on the team.</p><p>You must also be aware of <a href="https://github.com/">Github</a> which is a very popular service that helps developers maintain their Git repositories online and enable easy collaboration by acting as the central <a href="https://poddarayush.com/shorts/git-storage-of-versions/">version database</a>.</p><p>In this post, I am interested in introducing you to the concept of <strong>Git remotes</strong>. The repository that you have uploaded to Github is an example of a <strong>Git remote</strong>. It is basically a copy of your local Git repository that is accessible to anyone you choose to share your repository with.</p><h3>There can be more than one remote</h3><p>Your repository can have multiple remotes, i.e., multiple remote copies of the repository with different read/write permissions for different users. A common case for multiple remotes is in the world of open source projects.</p><p>Generally, contributors clone the primary project repository and maintain their own remote copy of the repository <em>(ever heard of forking?)</em>, where they push any changes they make. After they are sure of the changes they have made, they request the project maintainers to pull those changes into the primary repository.</p><p>A Git remote is represented by the URL of the repository. You must have seen URLs which are of the form git://github.com/&lt;username&gt;/&lt;repo-name&gt;. Since remembering URLs is difficult, Git also allows you to assign <strong>shortnames</strong> that map to these URLs. By default, when you clone a Git repository, Git assigns the shortname origin to the URL from where you have cloned.</p><h3>How to list all remotes?</h3><p>The command git remote lists all the remotes associated with your repository. Without any options, it just lists the shortnames. If you want to view the associated URLs too, then you need to use the--verbose (-v) option. Below is the sample output of the git remote -v command.</p><pre>origin git@github.com:ayushpoddar/colorls.git (fetch)<br>origin git@github.com:ayushpoddar/colorls.git (push)<br>upstream https://github.com/athityakumar/colorls.git (fetch)<br>upstream https://github.com/athityakumar/colorls.git (push)</pre><h3>How to add a remote repository?</h3><p>Apart from the default origin remote, you can add a remote to your repository explicitly. The command for doing so is:</p><pre>git remote add &lt;shortname&gt; &lt;url&gt;</pre><p>The shortname can be anything that you choose. As an example, you can add a remote named upstream with the following command:</p><pre>git remote add upstream https://github.com/athityakumar/colorls.git</pre><p>In order to fetch all the information from this new remote, you could run git fetch &lt;shortname&gt;. For example, running git fetch upstream in context of the above examples will output:</p><pre>remote: Enumerating objects: 4, done.<br>remote: Counting objects: 100% (4/4), done.<br>remote: Total 4 (delta 3), reused 4 (delta 3), pack-reused 0<br>Unpacking objects: 100% (4/4), 555 bytes | 61.00 KiB/s, done.<br>From https://github.com/athityakumar/colorls<br> * [new branch]      disable-mfa -&gt; upstream/disable-mfa<br>   d1e28ed..28c188b  main        -&gt; upstream/main</pre><p>You can now access upstream’s main branch at upstream/main.</p><blockquote>If you try to run git checkout upstream/main, Git will display an elaborate warning. I will get into the details of this warning in a later post.</blockquote><h3>Does “git fetch” make any modifications?</h3><p>No, it just downloads the repository data to your local repository. It does not merge any changes or modify any of your files.</p><h3>References</h3><ul><li><a href="https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes">https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes</a></li></ul><p><em>Originally published at </em><a href="https://poddarayush.com/posts/git-remote-commands/"><em>https://poddarayush.com</em></a><em> on August 13, 2023.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c73284565ae" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Un-stage and un-modify a file in Git — Part 2]]></title>
            <link>https://ayushpoddar.medium.com/un-stage-and-un-modify-a-file-in-git-part-2-93db4d9a327f?source=rss-7c284d9e368e------2</link>
            <guid isPermaLink="false">https://medium.com/p/93db4d9a327f</guid>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Ayush Poddar]]></dc:creator>
            <pubDate>Sat, 12 Aug 2023 03:13:40 GMT</pubDate>
            <atom:updated>2023-08-12T03:40:49.980Z</atom:updated>
            <content:encoded><![CDATA[<h3>Un-stage and un-modify a file in Git — Part 2</h3><p><em>This post is part of my </em><a href="https://poddarayush.com/shorts"><em>“Shorts”</em></a><em> series, where each post is concise and hyper-focused on a single concept.</em></p><p>In a <a href="https://poddarayush.com/shorts/unstage-a-file/">previous post</a>, we learned about the git rm command which helps you un-stage a file, and delete any modifications made. However, the git rm command is essentially meant to &quot;delete&quot; files, not undo them.</p><p>Git offers a dedicated command to undo modifications, or undo staging of a file. In this post, I will introduce you to git restore which can be used to perform both these tasks.</p><blockquote>Git introduced git restore in version 2.23.0. Earlier, the commands git reset and git checkout were used for the same purposes. But, git restore was introduced as a more dedicated tool for these specific purposes.</blockquote><p>I will not cover the details of the git restore command since Git is very helpful with these commands, and I think it is best for you to explore them yourself. When you run git status, Git exactly tells you the commands to un-stage or undo any unstaged modifications. This is how the output of git status looks like. Notice the commands mentioned for undo-ing.</p><pre>On branch main<br>Your branch is ahead of &#39;origin/main&#39; by 1 commit.<br>  (use &quot;git push&quot; to publish your local commits)<br><br>Changes to be committed:<br>  (use &quot;git restore --staged &lt;file&gt;...&quot; to unstage)<br> renamed:    README.md -&gt; README<br><br>Changes not staged for commit:<br>  (use &quot;git add &lt;file&gt;...&quot; to update what will be committed)<br>  (use &quot;git restore &lt;file&gt;...&quot; to discard changes in working directory)<br> modified:   ammend.md</pre><h3>Fair warning</h3><p>If you use git restore &lt;file&gt; to undo any unstaged modifications to a file, then you will lose all those changes forever. Git only helps you recover changes that have ever been committed.</p><p>If you are feeling uneasy about losing those modifications forever, but still want to undo the modifications, a better way is to use git stash. I will explore this command in a later post.</p><h3>Further exploration</h3><p>As always, I encourage you to explore the command further using man git-restore.</p><p><em>Originally published at </em><a href="https://poddarayush.com/shorts/basic-git-undo/"><em>https://poddarayush.com</em></a><em> on August 12, 2023.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=93db4d9a327f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Less is more — Limit the size of your Git log output]]></title>
            <link>https://towardsdev.com/less-is-more-limit-the-size-of-your-git-log-output-975128aea394?source=rss-7c284d9e368e------2</link>
            <guid isPermaLink="false">https://medium.com/p/975128aea394</guid>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Ayush Poddar]]></dc:creator>
            <pubDate>Fri, 11 Aug 2023 05:44:53 GMT</pubDate>
            <atom:updated>2023-08-12T12:05:45.300Z</atom:updated>
            <content:encoded><![CDATA[<h3>Less is more — Limit the size of your Git log output</h3><p>In the <a href="https://poddarayush.com/posts/viewing-git-logs">previous post</a>, we learned how to customise the output of the git log command. That post dealt with the presentation of the logs.</p><p>When we run the git log command, we generally do it to answer a question that we have. Those questions can be anything:</p><ul><li>When was this function last changed?</li><li>What were the last 3 commits?</li><li>What were the commits done by the X co-worker?</li><li>Any other question</li></ul><p>Essentially, log of all the commits is generally useless to us. We, often, only need a subset of the log to find an answer to our questions. In this post, I will introduce you to some of the options supported by git log that helps us limit the number of commits that are displayed.</p><h3>View the last n commits</h3><p>You can use git log -&lt;n&gt;, where n is any integer to show the last n commits. For example, running git log -3 will return the last 3 commits in the log.</p><h3>View the commits made since X date</h3><p>You can use git log --since=&lt;date&gt;, where date is either a specific date (like 2023-06-22 in <strong>YYYY-MM-DD</strong> format) or a relative date (like &quot;2 days 1 hour ago&quot;) to show all the commits made since a certain date. For example, running git log --since=&quot;2 days ago&quot; will return all the commits made in the last 2 days.</p><blockquote><em>I encourage you to explore </em><em>man git-log to learn about other formats supported by the </em><em>--since flag.</em></blockquote><h3>View the commits whose patch contains X string</h3><p>Often times, you need to search for a commit whose patch contains a certain string. For instance, you may be want to know which commit changed the API error message in your code.</p><p>The -S flag can be used to search for commits whose patch contains a certain string. In order to view what exactly matched, this flag is best used with the flag.</p><p>For example, running git log -S &quot;error&quot; will return all the commits whose patch contains the string &quot;error&quot;. The output of the command git log -S &quot;change&quot; -p is shown below. Notice the string &quot;change&quot; in the last line of the diff output.</p><pre>commit 596cb31a2d6e961ebc1fd413a384c342e19543f5<br>Author: Ayush Poddar &lt;ayush.mail.id@gmail.com&gt;<br>Date:   Thu Jul 27 10:40:19 2023 +0530<br><br>    Update bat.md<br><br>diff --git a/bat.md b/bat.md<br>index a5c1966..6dda867 100644<br>--- a/bat.md<br>+++ b/bat.md<br>@@ -1 +1,3 @@<br> Hello, world<br>+<br>+Making a change after removing it from index in local</pre><h3>View the commits where a specific file(s) changed</h3><p>You may be wanting to view the commits where a certain file/files was/were changed. The command looks like this: git log -- &lt;filepath&gt;, where filepath can be the path to files you are investigating. The -- (double dashes) is used to separate the options provided to git log from &lt;filepath&gt;. If a list of file paths are provided, then all the commits where <strong>ANY one</strong> of the files was changed is returned. It basically acts as a <strong>OR</strong> matcher instead of <strong>AND</strong> matcher.</p><p>For example, the sample output of running git log --stat -- ammend.md foo.txt is shown below. I have used the --stat option so that I can show you that only the commits where either ammend.md OR foo.txt changed are outputted.</p><pre>commit 1062877fc12c3b3d54ca17f539abc71ccb3cc324<br>Author: Ayush Poddar &lt;ayush.mail.id@gmail.com&gt;<br>Date:   Wed Aug 9 09:47:20 2023 +0530<br><br>    some change<br><br> foo.txt | 1 +<br> 1 file changed, 1 insertion(+)<br><br>commit 596cb31a2d6e961ebc1fd413a384c342e19543f5<br>Author: Ayush Poddar &lt;ayush.mail.id@gmail.com&gt;<br>Date:   Thu Jul 27 10:40:19 2023 +0530<br><br>    Update bat.md<br><br> ammend.md | 3 +++<br> 1 file changed, 3 insertions(+)</pre><h3>More options</h3><p>git log supports more options. The best way to explore them would be to use man git-log. Here are some of the most common ones:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*2C9H8t9IZMB8YcdQuRk7nA.png" /></figure><blockquote><em>It is possible to specify more than one instance of </em><em>--grep and </em><em>--author search criteria. In other words you can do this: </em><em>git log --grep foo --author Ayush --grep bar --author Candy. In such cases, the output will be those commits which match </em><strong><em>ANY</em></strong><em> of the authors provided </em><strong><em>and</em></strong><em> </em><strong><em>ANY</em></strong><em> of the </em><em>grep patterns.<br> If you want commits which match </em><strong><em>ALL</em></strong><em> the </em><em>grep patterns provided, then you can use the </em><em>--all-match flag. For example: </em><em>git log --all-match --grep foo --grep bar will output all commits whose commit messages contain both </em><em>foo </em><strong><em>AND</em></strong><em> </em><em>bar.<br></em><em>--all-match only works for </em><em>--grep. In fact, you do not need it for </em><em>--author since any commit will have only one author.</em></blockquote><h3>Final words</h3><p>A key part of root cause investigations is browsing your Git logs. You go through the Git logs to figure out which exact change caused the bug and why was the change made.</p><p>Now you are in the position to do so more efficiently. You can use a combination of the options shown in this post and the <a href="https://poddarayush.com/posts/viewing-git-logs">previous post</a> to speed up your investigations.</p><h3>Source</h3><ul><li><a href="https://git-scm.com/book/en/v2/Git-Basics-Viewing-the-Commit-History">https://git-scm.com/book/en/v2/Git-Basics-Viewing-the-Commit-History</a></li></ul><p><em>Originally published at </em><a href="https://poddarayush.com/posts/limit-git-log-output/"><em>https://poddarayush.com</em></a><em> on August 11, 2023.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=975128aea394" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/less-is-more-limit-the-size-of-your-git-log-output-975128aea394">Less is more — Limit the size of your Git log output</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Customise how you view your Git commit logs with these options]]></title>
            <link>https://ayushpoddar.medium.com/customise-how-you-view-your-git-commit-logs-with-these-options-b99330d6ffbf?source=rss-7c284d9e368e------2</link>
            <guid isPermaLink="false">https://medium.com/p/b99330d6ffbf</guid>
            <category><![CDATA[logging]]></category>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Ayush Poddar]]></dc:creator>
            <pubDate>Thu, 10 Aug 2023 10:34:09 GMT</pubDate>
            <atom:updated>2023-08-10T11:54:02.350Z</atom:updated>
            <content:encoded><![CDATA[<p>Viewing your Git commit logs is an important part of a software development process. Git provides the powerful git log to help us to do so. By default, this command displays the commit hash, author, date and the message for each commit. But, sometimes, you may feel the need to view more details on each log, or may be just quickly glance over the logs.</p><p>In this post, we will explore some of the most common options provided by Git for git log which can be used to customise how you view your commit logs.</p><h3>View all the changes associated with each commit</h3><p>Using the --patch (or -p) command line flag with git log displays the changes made to each commit. The sample output of the command git log -p is shown below. <em>Notice the details of changes shown under each commit.</em></p><pre>commit 1062877fc12c3b3d54ca17f539abc71ccb3cc324<br>Author: Ayush Poddar &lt;ayush.mail.id@gmail.com&gt;<br>Date:   Wed Aug 9 09:47:20 2023 +0530<br><br>    some change<br><br>diff --git a/foo.txt b/foo.txt<br>new file mode 100644<br>index 0000000..1a76b8a<br>--- /dev/null<br>+++ b/foo.txt<br>@@ -0,0 +1 @@<br>+Some random text<br><br>commit 596cb31a2d6e961ebc1fd413a384c342e19543f5<br>Author: Ayush Poddar &lt;ayush.mail.id@gmail.com&gt;<br>Date:   Thu Jul 27 10:40:19 2023 +0530<br><br>    Update bat.md<br><br>diff --git a/ammend.md b/ammend.md<br>new file mode 100644<br>index 0000000..2cb4113<br>--- /dev/null<br>+++ b/ammend.md<br>@@ -0,0 +1,3 @@<br>+To be ammended<br>+<br>+To be ammended - 2<br>diff --git a/bat.md b/bat.md<br>index a5c1966..6dda867 100644<br>--- a/bat.md<br>+++ b/bat.md<br>@@ -1 +1,3 @@<br> Hello, world<br>+<br>+Making a change after removing it from index in local</pre><h3>View stats associated with each commit</h3><p>Viewing all the change details for each commit can get overwhelming sometimes. You may want to just get the stats associated with each commit, i.e., view the number of lines added/deleted in each commit. The --stat flag with git log will help you achieve this. Sample output of the command git log --stat is shown below.</p><pre>commit 1062877fc12c3b3d54ca17f539abc71ccb3cc324<br>Author: Ayush Poddar &lt;ayush.mail.id@gmail.com&gt;<br>Date:   Wed Aug 9 09:47:20 2023 +0530<br><br>    some change<br><br> foo.txt | 1 +<br> 1 file changed, 1 insertion(+)<br><br>commit 596cb31a2d6e961ebc1fd413a384c342e19543f5<br>Author: Ayush Poddar &lt;ayush.mail.id@gmail.com&gt;<br>Date:   Thu Jul 27 10:40:19 2023 +0530<br><br>    Update bat.md<br><br> ammend.md | 3 +++<br> bat.md    | 2 ++<br> 2 files changed, 5 insertions(+)</pre><h3>Change the output format</h3><p>The --pretty flag with git log can be used to change the format of the output. The --pretty flag takes in a value which determines the format of the output.</p><h4>View each commit in a single line</h4><p>The value oneline prints each commit in a single line. Sample output of git log --pretty=oneline is given below.</p><pre>1062877fc12c3b3d54ca17f539abc71ccb3cc324 some change<br>596cb31a2d6e961ebc1fd413a384c342e19543f5 Update bat.md</pre><h4>Other values</h4><p>There are other values as well like short, full and fuller. As the names suggest, they determine how verbose your commit logs will be. I encourage you to try out each of these values by yourself. For example: You could try out git log --pretty=full</p><h4>Customise the output format</h4><p>You can also customise your log output as per your custom requirements by passing the value format to the--pretty flag. The sample output of the command git log --pretty=format:&quot;%h - %an, %ar : %s&quot; is shown below.</p><pre>1062877 - Ayush Poddar, 31 hours ago : some change<br>596cb31 - Ayush Poddar, 2 weeks ago : Update bat.md</pre><p>Some of the most useful specifiers for --pretty=format is given below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/1*7gPRHUpfhsVxQ7_ZyHXYPA.png" /><figcaption>git log format specifiers</figcaption></figure><h3>View the branch and merge history</h3><p>The --graph flag displays a ASCII graph showing your branch and merge history. It is particularly useful when used with--pretty=oneline option. I encourage you to try this out with different values for--pretty to know why I have written so. The sample output of git log --graph --pretty=oneline is shown below.</p><pre>* 305e2486f4431fc7e0487423f90ed380852194b2 refactor: split into two methods<br>* 6f7f4ab47d0a1d8fdf86fcf9b6f27fde34f1ef1e modify the instance doubles ensuring green specs<br>* fe59bb7c5f7f2b69e11902dda063f5ab487e57c7 add logic to show different color for hidden files/directories<br>* 4f1333ff66cb6510d95d01f65997147b95a80c86 add colors for hidden files/directories<br>* 1e1f10c7635ea0126eadb28f8f31c8ec38a77695 modify indentations<br>*   28c188bbd62ba47072c26fbc1124f9e4288a7932 Merge pull request #594 from ayushpoddar/show-abs-path-xargs<br>|\  <br>| * 44c370b4c6f5b384f10a95a9bbacca627328800c Revert &quot;version bump&quot;<br>| * 414820b23bfdcf0a386614b3ad2efd2a31431c18 version bump<br>| * c5fdcf6e9261809e1e3e3738e85fa52f9115e5ae relevant feature spec<br>| * 86daeef7ec8b504085b8388da331d6b8cd5f0c87 rubocop fixes<br>| * 1001aa28327fd91d18e198187d93e0ca5d2cf223 refactor: DRY the fileinfo stub for spec readability<br>| * 4c5ef39093593d579cc861870a98d20fc1fa02b5 fix the stubs in specs<br>| * 688188de6f37eda67ebbffe0e996196bb073ae9b show relative filepath when argument is file<br>|/  <br>*   d1e28edcd0721ff0e082b041eba35e12ffae0af4 Merge pull request #589 from ayushpoddar/size-in-bytes<br>|\  <br>| * 5f3b8807d3865339327b68a622e81869f20cb411 spec fix: not more than 3 lines in the spec output<br>| * 03ebc748ad9052b88d94f24f3fc14faf804214bf add check for the new flag<br>| * 93fa6872c9fe4c6349644a22b7cd912010ee0473 remove --nh flag<br>| * d4fdd94d97c72f8b386cea21b890ce54e6081b26 justify size unit only when displaying human readable sizes<br>| * d11bd9241fa8e5bb241d758d9afc3e1c6b97e4a6 update the version as per semantic versioning specification<br>| * 346ec6c53e8ba8c6fa19e87ae85336afd3e8346f update the readme<br>| * 214cb436e28bc5027f968ce1aba8f4267da491d5 silence rubocop<br>| * 69988e1b2e602502815c8cf7ae8096c648c4537d improve the regex<br>| * 81ced364a4cc851be86425587dbfe419ab781e67 fix: fix failing spec due to new fixture file<br>| * 7eda794a07a125917a1cbf606c628f120550f2ea spec: add spec to flags spec<br>| * 0421206076465ab9845bf2c51e287d759d35038d rubocop fix<br>| * 6f5abb25a0d9e72af40b91708ccf75d6de561b6b increase the number of characters allotted to displaying size<br>| * e231708f30996ccd76057185e0e501a926d8c840 add support for --non-human-readable flag<br>* |   23a1b726792dc6d715c31d6f0213fd12ccfb8c58 Merge pull request #590 from athityakumar/dependabot/bundler/rubocop-rspec-tw-2.20.0<br>|\ \  <br>| |/  <br>|/|</pre><h3>Final words</h3><p>Being able to control how the commit logs are displayed to you can help you analyse your repository quickly and more efficiently. You may require different amount of detail in your logs at different times depending on your use case.</p><p>After reading this post, you are in a better position to control the verbosity of your commit logs.</p><h3>Further exploration</h3><ul><li>Play around with some of the flags mentioned in this post. Try out combinations of flags.</li><li>You can view more <a href="https://git-scm.com/book/en/v2/ch00/log_options">supported options here</a>.</li></ul><h3>Sources</h3><ul><li><a href="https://git-scm.com/book/en/v2/Git-Basics-Viewing-the-Commit-History">https://git-scm.com/book/en/v2/Git-Basics-Viewing-the-Commit-History</a></li></ul><p><em>Originally published at </em><a href="https://poddarayush.com/posts/viewing-git-logs/"><em>https://poddarayush.com</em></a><em> on August 10, 2023.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b99330d6ffbf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Un-stage (rm) a file in Git]]></title>
            <link>https://ayushpoddar.medium.com/un-stage-rm-a-file-in-git-315036bcffbd?source=rss-7c284d9e368e------2</link>
            <guid isPermaLink="false">https://medium.com/p/315036bcffbd</guid>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Ayush Poddar]]></dc:creator>
            <pubDate>Wed, 09 Aug 2023 04:07:18 GMT</pubDate>
            <atom:updated>2023-08-09T04:49:12.782Z</atom:updated>
            <content:encoded><![CDATA[<p><em>This post is part of my </em><a href="https://poddarayush.com/shorts"><em>“Shorts”</em></a><em> series, where each post is concise and hyper-focused on a single concept.</em></p><p>You have used the <a href="https://poddarayush.com/posts/git-add-versatility/">git add command</a> to stage a file. But, if you accidentally stage an undesired file (like a log file), then how do you un-stage it?</p><h3>The git-rm command</h3><p>The command will work in this manner:</p><pre>git rm --cached /path/to/file</pre><p>The --cached flag specifically refers to the staging area. This command un-does the effect of git add /path/to/file command</p><h3>What does the command do without the flag?</h3><p>You must be familiar with the plain old unix rm command which deletes a file from your local disk. git rm is similar with some added flavor.</p><blockquote>git rm does not work on newly created files. It only works on <a href="https://poddarayush.com/posts/git-add-versatility/">tracked files</a>.</blockquote><p>First, lets revisit the <a href="https://poddarayush.com/shorts/three-states-of-git/">states of a file</a> in a Git repository. A tracked file can be unmodified, modified or staged before being committed.</p><h3>In case of unmodified file</h3><p>git rm /path/to/file does two things:</p><ol><li>Deletes the file from your local disk</li><li>Adds this change (deletion of file) to the staging area.</li></ol><p>In essence it is equivalent to:</p><pre>rm /path/to/file<br>git add /path/to/file</pre><h3>In case of modified file or staged file</h3><p>You need to use the --force (or -f) flag. This is a safety feature since any modification is not saved in any of your previous version snapshots. If you run git rm on a modified or staged file as it is, then Git will throw an error.</p><p>Adding the --force option deletes the file from your local disk and stages this change (deletion of file).</p><blockquote>You may have noticed that usage of --cached flag on staged files does not delete the files from the local disk. It only un-stages the files.</blockquote><h3>Further exploration</h3><p>Run man git-rm in your terminal to learn more about using git rm.</p><h3>Sources</h3><ul><li><a href="https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository">https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository</a></li></ul><p><em>Originally published at </em><a href="https://poddarayush.com/shorts/unstage-a-file/"><em>https://poddarayush.com</em></a><em> on August 9, 2023.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=315036bcffbd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[View the changes you have made to your Git repository — Intro to git-diff]]></title>
            <link>https://ayushpoddar.medium.com/view-the-changes-you-have-made-to-your-git-repository-intro-to-git-diff-799dde51624c?source=rss-7c284d9e368e------2</link>
            <guid isPermaLink="false">https://medium.com/p/799dde51624c</guid>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Ayush Poddar]]></dc:creator>
            <pubDate>Tue, 08 Aug 2023 14:26:03 GMT</pubDate>
            <atom:updated>2023-08-08T17:58:03.564Z</atom:updated>
            <content:encoded><![CDATA[<h3>View the changes you have made to your Git repository — Intro to git-diff</h3><p><em>This post is part of my </em><a href="https://poddarayush.com/shorts"><em>“Shorts”</em></a><em> series, where each post is concise and hyper-focused on a single concept.</em></p><p>In an <a href="https://poddarayush.com/posts/git-add-versatility/">earlier post</a>, we discussed how you can stage changes that you make in your Git repository.</p><p>What if you want to view the changes you have made before staging your changes? What if you want to view the changes that are there in the staging area before you commit your changes? In this post, I will tell you about git diff which can help you with these questions.</p><h3>About the command</h3><p>The command simply is:</p><pre>git diff &lt;filePath&gt;</pre><p>where &lt;filePath&gt; is the path to a file whose changes you want to view. The argument &lt;filePath&gt; is optional. If you don&#39;t specify the path, git diff will display the changes from all the modified files.</p><p>As it is, this command will show you all the changes you have made to your <a href="https://poddarayush.com/shorts/three-states-of-git/">working tree</a> that are ready to be staged.</p><h4>How to view the staged changes?</h4><p>If you want to view the staged changes, i.e., the changes that are ready to be committed, you should use the --staged (or --cached) command line flag.</p><pre>git diff --staged</pre><h3>Further exploration</h3><p>Run man git-diff in your terminal to learn more about using git diff.</p><h3>Sources</h3><ul><li><a href="https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository">https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository</a></li></ul><p><em>Originally published at </em><a href="https://poddarayush.com/shorts/git-diff-intro/"><em>https://poddarayush.com</em></a><em> on August 8, 2023.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=799dde51624c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Use your gitignore efficiently — Learn supported patterns.]]></title>
            <link>https://ayushpoddar.medium.com/use-your-gitignore-efficiently-learn-supported-patterns-e9c3e50138e9?source=rss-7c284d9e368e------2</link>
            <guid isPermaLink="false">https://medium.com/p/e9c3e50138e9</guid>
            <category><![CDATA[git]]></category>
            <category><![CDATA[gitignore]]></category>
            <dc:creator><![CDATA[Ayush Poddar]]></dc:creator>
            <pubDate>Sun, 06 Aug 2023 08:09:58 GMT</pubDate>
            <atom:updated>2023-08-07T05:47:44.843Z</atom:updated>
            <content:encoded><![CDATA[<h3>Use your gitignore efficiently — Learn supported patterns.</h3><p>📝 <em>This post is part of my “</em><a href="https://poddarayush.com/shorts"><em>Shorts</em></a><em>” series, where each post is concise and hyper-focused on a single concept.</em></p><p>.gitignore is an indispensable part of any Git project. It is used to maintain a list of files/directories that Git should not <a href="https://poddarayush.com/posts/git-add-versatility">track</a>. Those files can be anything: build files, tmp directories, log files, etc.</p><p>You may also have used this file when working on a software development project. In this post, I want to tell you about some of the patterns that can help you:</p><ol><li>Avoid weird bugs</li><li>Make your .gitignore more efficient</li></ol><p>For example, did you know that if your .gitignore file contains the following line, then all directories in your project named nestedDir will be ignored. It does not matter if the directory is in the root directory.</p><pre>nestedDir/</pre><p>One of the fundamental things to learn about .gitignore is to know that any pattern found in the.gitignore file will be searched for recursively in your repository and then, ignored.</p><h3>Patterns supported</h3><ul><li>Blank lines and lines starting with # are ignored. Lines starting with # can be considered as comments.</li><li>Standard glob patterns are supported <em>(more on this below)</em>.</li><li>Patterns starting with / avoid recursivity. For example, a pattern like /rootFile will only ignore therootFile present in the root of the repository.</li><li>In order to specify a directory, end the pattern with a /.</li><li>Patterns starting with ! will be negated. For example, if your .gitignore contains *.log (ignoring all log files) but you want to trackproduction.log file specifically, you need to add!production.log to your .gitignore.</li></ul><h3>Examples</h3><pre># Ignore all log files present anywhere in the repository<br>*.log<br><br># But, track the production.log file<br>!production.log<br><br># Ignore the config.yaml file present in the root directory ONLY<br>/config.yaml<br><br># Ignore all directories named `posts` present anywhere in the repository<br>posts/<br><br># Ignore all txt files which are present directly inside manual directory<br>manual/*.txt<br><br># Ignore all exe files which are present inside the bin directory and its subdirectories<br>bin/**/*.exe</pre><p>You can also look up the list of good .gitignore <a href="https://github.com/github/gitignore">file examples here</a>.</p><h3>Understanding basic glob patterns</h3><ul><li>Asterisk (*) matches zero or more characters. Example: *.log would match any file ending with.log.</li><li>Question mark (?) matches one character. Example: ?.log would match files like 1.log,p.log but not match test.log.</li><li>If you list characters inside square brackets ([]), it would match all files/directories containing any of those characters. Example:[abc].log will match a.log, b.log, c.log but not abc.log or d.log.</li><li>Square brackets also supports ranges. So, [12345] is equivalent to [1-5].</li><li>Double asterisks (**) will match nested directories. Example: a/**/z will match a/z,a/b/z, a/b/c/z and so on.</li></ul><h3>One more thing</h3><p>It is not necessary to have only one .gitignore file per repository. You can create separate .gitignore files for subdirectories. The rules in a.gitignore will be applied on the files under the directory where each.gitignore is located.</p><h3>What’s your ONE takeaway?</h3><p>When I learned about these patterns, one of the biggest takeaways for me was that the rules are applied recursively on all subdirectories. What’s yours? Tell me about it on <a href="/service/mailto:ayush.mail.id@gmail.com">my email</a>.</p><h3>Further exploration</h3><p>Run man gitignore in your terminal to learn more about using .gitignore.</p><h3>Sources</h3><ul><li><a href="https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository">https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository</a></li></ul><p><em>Originally published at </em><a href="https://poddarayush.com/shorts/maintaining-gitignore"><em>https://poddarayush.com</em></a><em> on August 7, 2023.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e9c3e50138e9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>