<?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: anis dabdi</title>
    <description>The latest articles on DEV Community by anis dabdi (@ansdb).</description>
    <link>https://dev.to/ansdb</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%2F161418%2F6605d9fb-05ee-4d65-ae58-60f7d36ca7d8.jpg</url>
      <title>DEV Community: anis dabdi</title>
      <link>https://dev.to/ansdb</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ansdb"/>
    <language>en</language>
    <item>
      <title>10 helpful flags to use with git log command.</title>
      <dc:creator>anis dabdi</dc:creator>
      <pubDate>Tue, 25 Feb 2020 15:12:57 +0000</pubDate>
      <link>https://dev.to/ansdb/10-helpful-flags-to-use-with-git-log-command-1l3k</link>
      <guid>https://dev.to/ansdb/10-helpful-flags-to-use-with-git-log-command-1l3k</guid>
      <description>&lt;p&gt;I’m part of the &lt;a href="https://sites.google.com/udacity.com/bertelsmann-challenge/" rel="noopener noreferrer"&gt;Cloud DevOps Bertelesman Udacity phase 1 scholarship program&lt;/a&gt;, and I’m participating in one of the optional challenges, the blog challenge which is to write a blog about one of the course Lessons, and I decided to write this blog about logging in git (VCS).&lt;/p&gt;

&lt;p&gt;In this guide you’ll advance your capabilities of searching in the history of your repositories while working on your own projects, this will help a lot with tracking your changes and your teammate's changes as well.&lt;/p&gt;

&lt;p&gt;We know that when it comes to logging or let’s say log files, it’s all about investigating or searching in the history for sure of your system or program that you’re working on, to know what’s going on with your stuff and check the current state of your system or program.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NB:&lt;/strong&gt; &lt;em&gt;this guide will be as short as possible, so I will list just git commands with flags, and a short description to give you an overview of what this flag does, in this guide, we’re assuming &lt;code&gt;master&lt;/code&gt; as our main branch, so whenever I talk about something it’s from &lt;code&gt;master&lt;/code&gt; main branch perspective, let’s get started.&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;git log&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This command is the base of everything we will discuss here in this guide, this command lists all the commits you have in your repository with the following information (commit SHA, date, author email, username and commit message) but in the current branch you’re in, let’s say &lt;code&gt;master&lt;/code&gt; branch. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;git log --oneline&lt;/code&gt;&lt;/li&gt;
&lt;/ul&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%2Ftnhnixwlt7rk81528ryb.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%2Ftnhnixwlt7rk81528ryb.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;--oneline&lt;/code&gt; flag lists all the commits as &lt;code&gt;git log&lt;/code&gt; does, but just in one line with the first 7 characters SHA + the commit message as shown above in the image.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;git log --all&lt;/code&gt;&lt;/li&gt;
&lt;/ul&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%2F7f39e2lpuq5gpkso2dc7.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%2F7f39e2lpuq5gpkso2dc7.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This command lists all the commits that are not yet merged in our main branch, usually from other local branches, &lt;em&gt;current branch commits + other branches commits&lt;/em&gt;, as you see over there in the image, there is a commit listed from the &lt;code&gt;feature-branch&lt;/code&gt; even if we're just in &lt;code&gt;master&lt;/code&gt; branch.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;git log --merges&lt;/code&gt;&lt;/li&gt;
&lt;/ul&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%2Fc6qgz0tu21pigptojax7.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%2Fc6qgz0tu21pigptojax7.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This command lists just the merged commits, which means just the commits coming from merge conflicts. Like if &lt;code&gt;feature-branch&lt;/code&gt; gets merged into the &lt;code&gt;master&lt;/code&gt; branch, conflict should be resolved before completing the merge, and a merge commit is added to the commits that state the conflict resolved between the content of same commits from different branches, these kind of commits will be listed alone using this command. it has its opposite command which is  &lt;code&gt;--no-merges&lt;/code&gt; which do the opposite and lists all none merge commits, as you see in the image below the above merge commit doesn't appear here with the opposite &lt;code&gt;--no-merge&lt;/code&gt; flag.&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%2Fko7es5x0hhkupf81v9uk.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%2Fko7es5x0hhkupf81v9uk.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;git log --patch&lt;/code&gt;&lt;/li&gt;
&lt;/ul&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%2F7nqll4f7yrtt4yk5a4on.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%2F7nqll4f7yrtt4yk5a4on.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There is a shorthand for this command which is &lt;code&gt;–p&lt;/code&gt;, what this flag actually does is just listing the commits as &lt;code&gt;git log&lt;/code&gt; does, but with the changes happened in this commit as well, the + sign means the additional lines of code added to the file/s in this commit, – sign shows the removed parts of code from the file/s in this commit and the white text means it's kept as it is, no changes happen to it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;git log --stat&lt;/code&gt;&lt;/li&gt;
&lt;/ul&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%2F4fdcqn75r2llikp26lbr.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%2F4fdcqn75r2llikp26lbr.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stat&lt;/strong&gt; stands for &lt;em&gt;statistics&lt;/em&gt;, it lists all the commits with the files and the exact number of changes that happened in each file.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;git log –S”&amp;lt;string&amp;gt;”&lt;/code&gt;&lt;/li&gt;
&lt;/ul&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%2F7aqphyhagj3w4sxgam8p.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%2F7aqphyhagj3w4sxgam8p.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This flag is wonderful, it helps you to search for a specific text inside your files, let’s say you search about some names you put on an &lt;code&gt;HTML&lt;/code&gt; file and you want to know in how many commits these names reside.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;git log --grep=”value here”&lt;/code&gt;&lt;/li&gt;
&lt;/ul&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%2Frvr69umwv8jx92qg3f6x.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%2Frvr69umwv8jx92qg3f6x.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This flag helps a lot if you want to search for a specific commit in terms of a commit message, just put your piece of text you want to search for in commit messages and all the commits match the piece of text you provided will be listed.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;git log --author=”username or email”&lt;/code&gt;&lt;/li&gt;
&lt;/ul&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%2Fmpr4srgbdv4xxc5oq331.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%2Fmpr4srgbdv4xxc5oq331.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sometimes you might want filtering commits by author &lt;em&gt;username&lt;/em&gt; or &lt;em&gt;email&lt;/em&gt; because author here means his username or his email, so you could put one of them in between quotes as a string value, you can also search for two authors in the same time with &lt;strong&gt;OR&lt;/strong&gt; operator in the following format: &lt;/p&gt;

&lt;p&gt;&lt;code&gt;git log --author=”username1\|username2”&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We used &lt;em&gt;slash&lt;/em&gt; here as an escape character, because we're dealing with a &lt;em&gt;string&lt;/em&gt; and this last one should be provided or the &lt;strong&gt;OR |&lt;/strong&gt; operator will be considered as one character of the whole username, as in any programming languages like &lt;em&gt;JavaScript&lt;/em&gt; especially in &lt;em&gt;RegExp&lt;/em&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;git log -&amp;lt;n&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&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%2F1ool1sbyr7odfb9bhq21.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%2F1ool1sbyr7odfb9bhq21.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;/em&gt; should be replaced by a number in order to list the most &lt;em&gt;&lt;/em&gt; recent commits, consider the following command &lt;code&gt;git log -3&lt;/code&gt;, this one will list the most &lt;strong&gt;three&lt;/strong&gt; recent commits.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;git log -- file1&lt;/code&gt;&lt;/li&gt;
&lt;/ul&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%2F32lvi891xzb2q9eb1acc.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%2F32lvi891xzb2q9eb1acc.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also list commits by files, for example, &lt;code&gt;git log -- index.html&lt;/code&gt; you can add multiple files, &lt;code&gt;git log -- index.html  script.sh&lt;/code&gt;, and this last command lists all the commits that track the changes in these two files &lt;code&gt;index.html&lt;/code&gt; and &lt;code&gt;script.html&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;All the above &lt;em&gt;flags&lt;/em&gt; work together, so combine them whenever you need the output in such a desired format.&lt;/p&gt;

&lt;p&gt;I hope you enjoyed this blog and it helps you to expand your knowledge in git.&lt;/p&gt;

</description>
      <category>git</category>
      <category>vcs</category>
      <category>opensource</category>
      <category>github</category>
    </item>
  </channel>
</rss>
