<?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: M. Safarian</title>
    <description>The latest articles on DEV Community by M. Safarian (@safarian).</description>
    <link>https://dev.to/safarian</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%2F1367556%2Ffb9edf36-552b-490f-bb67-9a79825b87c0.jpg</url>
      <title>DEV Community: M. Safarian</title>
      <link>https://dev.to/safarian</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/safarian"/>
    <language>en</language>
    <item>
      <title>Git Snapshot | Steps | Workflow — 2</title>
      <dc:creator>M. Safarian</dc:creator>
      <pubDate>Wed, 20 Mar 2024 06:39:48 +0000</pubDate>
      <link>https://dev.to/safarian/git-snapshot-steps-workflow-2-5h86</link>
      <guid>https://dev.to/safarian/git-snapshot-steps-workflow-2-5h86</guid>
      <description>&lt;p&gt;In &lt;a href="https://dev.to/safarian/git-snapshot-steps-workflow-1-369h"&gt;previous article&lt;/a&gt;, I covered the fundamental commands and steps necessary to create Git snapshots, also known as “committing changes”. However, in this piece, I aim to delve deeper into the report generated by Git after a commit, Git objects, how Git works under the hood&lt;/p&gt;




&lt;h1&gt;
  
  
  lets recap
&lt;/h1&gt;

&lt;p&gt;In the diagram below, we illustrate the workflow for committing a new file in Git:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3x1x6f7v80np30thpjtm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3x1x6f7v80np30thpjtm.png" alt="Git commit changes diagram" width="720" height="345"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After committing changes, Git provides us with a commit report. In this section, we’ll delve into the significance of the SHA-1 checksum, decipher the meaning of the last line in the report, and explore the inner workings of Git’s commit process.&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="nv"&gt;$ &lt;/span&gt;git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"this is init commit"&lt;/span&gt;

&lt;span class="o"&gt;[&lt;/span&gt;master &lt;span class="o"&gt;(&lt;/span&gt;root-commit&lt;span class="o"&gt;)&lt;/span&gt; ed942fe] this is init commit
1 file changed, 0 insertions&lt;span class="o"&gt;(&lt;/span&gt;+&lt;span class="o"&gt;)&lt;/span&gt;, 0 deletions&lt;span class="o"&gt;(&lt;/span&gt;-&lt;span class="o"&gt;)&lt;/span&gt;
create mode 100644 example.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First and foremost, it’s important to emphasize that Git captures snapshots of files, rather than recording the differences between versions. In other words, Git focuses on snapshots, not on differences (diffs) between versions. SNAPSHOT not DIFFS.&lt;/p&gt;

&lt;p&gt;Today, we will learn new terminologies and some commands that are not necessary during software development, but they allow us to understand Git’s operations under the hood.&lt;/p&gt;

&lt;h1&gt;
  
  
  Git Objects
&lt;/h1&gt;

&lt;p&gt;If you’ve worked with key-value databases like Redis before, the core concept of Git is easy to understand. Git functions as a key-value data storage system, allowing you to store various types of content and providing a unique hash string as a key in return. This hash string, typically of type SHA-1, enables you to retrieve the contents later.&lt;/p&gt;

&lt;p&gt;lets start with create a fresh local repository, after ‘init’ commad git creates a directory in of ‘.git’.&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="nv"&gt;$ &lt;/span&gt;git init example

Initialized empty Git repository &lt;span class="k"&gt;in&lt;/span&gt; /home/mehdi/git/example/.git/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In simple terms, the database I mentioned earlier will be located in the ‘.git’ directory. If you head to the ‘.git/objects’ directory, you’ll see ‘info’ and ‘pack’ subdirectories. They are belongs to Git and this is the place that Git uses as their object database.&lt;br&gt;
When you start a fresh repository there is nothing in ‘objects’ direcotry.&lt;br&gt;
There is a ‘hash-object’ command which create a data object and we can manually store data in Git key-value database and in return gives us a 40 character hash string in SHA-1.&lt;/p&gt;

&lt;p&gt;Before that, let’s check the ‘objects’ directory with the following command. As of now, it will return nothing.&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="nv"&gt;$ &lt;/span&gt;find .git/objects &lt;span class="nt"&gt;-type&lt;/span&gt; f
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, we’ll proceed to create our first data object manually using the ‘hash-object’ command. We’ll include additional flags like ‘-w’, which stands for write and indicates that we’re writing content into the database, and ‘-stdin’, which means we’ll read from stdin or the command-line.&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="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'Hello im mehdi'&lt;/span&gt; | git hash-object &lt;span class="nt"&gt;-w&lt;/span&gt; &lt;span class="nt"&gt;--stdin&lt;/span&gt;
4086ef4e53b8c4ab5a6aa37833db8c6c5032cf9d
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;lets check the &lt;strong&gt;‘objects’&lt;/strong&gt; directory&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="nv"&gt;$ &lt;/span&gt;find .git/objects &lt;span class="nt"&gt;-type&lt;/span&gt; f
.git/objects/40/86ef4e53b8c4ab5a6aa37833db8c6c5032cf9d
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;My ‘Hello, I’m Mehdi’ is stored in the Git database as an object. I can retrieve this data using the ‘cat-file’ command. The first two characters of the hash string represent the object directory, while the rest is a simple blob file, which I’ll discuss in the next part. Lets try to retrive our object in human readable output.&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="nv"&gt;$ &lt;/span&gt;git cat-file &lt;span class="nt"&gt;-p&lt;/span&gt; 4086ef4e53b8c4ab5a6aa37833db8c6c5032cf9d
Hello im mehdi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Good, Lets keep it short.&lt;/p&gt;

&lt;h2&gt;
  
  
  In conclusion
&lt;/h2&gt;

&lt;p&gt;we’ve explored the foundational concepts of Git, including its snapshot-based approach and key-value database structure. Understanding these core principles. We’ve also familiarized ourselves with new Git commands and terminologies, providing a solid foundation for further exploration and mastery of this powerful version control system. In next part we will read about “tree object” and blob files.&lt;/p&gt;

</description>
      <category>git</category>
      <category>software</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Git Snapshot | Steps | Workflow — 1</title>
      <dc:creator>M. Safarian</dc:creator>
      <pubDate>Wed, 20 Mar 2024 06:23:44 +0000</pubDate>
      <link>https://dev.to/safarian/git-snapshot-steps-workflow-1-369h</link>
      <guid>https://dev.to/safarian/git-snapshot-steps-workflow-1-369h</guid>
      <description>&lt;p&gt;While many people perceive Git as a confusing and complicated tool, it's actually quite simple once you become more familiar with it. Like many other areas of knowledge, all it takes is getting accustomed to it. Trust me, it's not as tangled as quantum physics.&lt;/p&gt;




&lt;h1&gt;
  
  
  Steps to create snapshot
&lt;/h1&gt;

&lt;p&gt;In order to snapshotting a working directory, there are some basic commands.&lt;br&gt;
&lt;code&gt;$ git status&lt;br&gt;
$ git add&lt;br&gt;
$ git commit&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;These tree commands represent two basic steps for capturing a snapshot of your working directory. While the 'status' command is merely informational, it's still beneficial to understand what it reveals about your actions :)&lt;br&gt;
lets imagine we created a repository in our local system and now we are going to add a file into them.&lt;br&gt;
first we check the status of our local repository by using 'status' commad:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git status
On branch master

No commits yet

Untracked files:
  &lt;span class="o"&gt;(&lt;/span&gt;use &lt;span class="s2"&gt;"git add &amp;lt;file&amp;gt;..."&lt;/span&gt; to include &lt;span class="k"&gt;in &lt;/span&gt;what will be committed&lt;span class="o"&gt;)&lt;/span&gt;
 example.txt

nothing added to commit but untracked files present &lt;span class="o"&gt;(&lt;/span&gt;use &lt;span class="s2"&gt;"git add"&lt;/span&gt; to track&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As we can see, there is nothing on our stage, and the file 'example.txt' is under the 'Untracked files' category. This generally indicates that Git doesn't care about that file until we add it to the stage and create a new snapshot. After that, Git will monitor all files that have taken at least one snapshot.&lt;br&gt;
The 'add' command is used to stage files, thereby indicating Git's awareness of them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git add example.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's check the status of our repository again to see what has changed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git status

On branch master

No commits yet

Changes to be committed:
  &lt;span class="o"&gt;(&lt;/span&gt;use &lt;span class="s2"&gt;"git rm --cached &amp;lt;file&amp;gt;..."&lt;/span&gt; to unstage&lt;span class="o"&gt;)&lt;/span&gt;
 new file:   example.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At this point, Git is actively tracking the file and is prepared to capture a snapshot of it, or in other words, the file is ready to be committed.&lt;br&gt;
lest see this workflow in a diagram.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnu4384w97xlocjh3skni.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnu4384w97xlocjh3skni.png" alt="Add to stage" width="800" height="384"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For our final action, we are going to create a commit message, and Git will take a snapshot of the current state of the repository.&lt;br&gt;
The '-m' flag allows us to use an inline commit message. Without it, Git will open the system's default editor(vscode, nano, vim, etc…).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"this is init commit"&lt;/span&gt;

&lt;span class="o"&gt;[&lt;/span&gt;master &lt;span class="o"&gt;(&lt;/span&gt;root-commit&lt;span class="o"&gt;)&lt;/span&gt; ed942fe] this is init commit
1 file changed, 0 insertions&lt;span class="o"&gt;(&lt;/span&gt;+&lt;span class="o"&gt;)&lt;/span&gt;, 0 deletions&lt;span class="o"&gt;(&lt;/span&gt;-&lt;span class="o"&gt;)&lt;/span&gt;
create mode 100644 example.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Congratulations, you've done it! &lt;br&gt;
That's precisely what's needed to keep track of changes to our files. &lt;br&gt;
In return, Git provides a report of what was committed. I'll discuss the details of this report in a separate document. However, generally, this report informs us that we committed on the master branch, and the SHA-1 checksum is 'ed942fe'. We can use this checksum to 'check-out' between our snapshots. In other words, this checksum is the signature of our snapshot, allowing Git to locate your target snapshot.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flgobnpbr3i7hevjamcvc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flgobnpbr3i7hevjamcvc.png" alt="Commit changes" width="800" height="384"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  In conclusion
&lt;/h2&gt;

&lt;p&gt;Git stands as one of the most prominent tools in the software world, particularly among programmers. Throughout this process, we've acquired the knowledge of adding new files to the staging area and committing changes, laying the groundwork for effective version control and collaboration in our software projects.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
