<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[Dmitry Churbanov]]></title>
  <link href="http://www.churbanov.com/blog/atom.xml" rel="self"/>
  <link href="http://www.churbanov.com/blog/"/>
  <updated>2012-12-03T02:18:35-08:00</updated>
  <id>http://www.churbanov.com/blog/</id>
  <author>
    <name><![CDATA[Dmitry Churbanov]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[Eclipse EGit plugin, part 2]]></title>
    <link href="http://www.churbanov.com/blog/2010/08/11/eclipse-egit-plugin-part-2/"/>
    <updated>2010-08-11T20:00:00-07:00</updated>
    <id>http://www.churbanov.com/blog/2010/08/11/eclipse-egit-plugin-part-2</id>
    <content type="html"><![CDATA[


<p>In the <a href="http://www.churbanov.com/blog/2010/07/12/eclipse-egit-plugin/">previous post</a> we discussed how to import remote
Git repository. Now let’s look what Git commands are available in EGit plugin. EGit plugin is still not completely
ready and does not support all Git commands. You can watch <a href="http://live.eclipse.org/node/885">“Understanding and Using Git at Eclipse”</a> webinar to learn what is ready and what the plans are.</p>

<p>In this post I will continue to use the same remote repository which was used in the <a href="http://www.churbanov.com/blog/2010/07/12/eclipse-egit-plugin/">previous post</a>.</p>

<h2>Basic operations</h2>

<p>In the <a href="http://www.churbanov.com/blog/2010/07/08/using-git-part-1/">first post</a> about Git we discussed the basic Git
operations. Now let’s see how you can do the same using EGit plugin.</p>

<h3>Add files</h3>

<p>Create <code>com.churbanov.tutorial.egit</code> package and the following two classes:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
</pre></td><td class='code'><pre><code class='java'><span class='line'><span class="kn">package</span> <span class="n">com</span><span class="o">.</span><span class="na">churbanov</span><span class="o">.</span><span class="na">tutorial</span><span class="o">.</span><span class="na">egit</span><span class="o">;</span>
</span><span class='line'>
</span><span class='line'><span class="cm">/**</span>
</span><span class='line'><span class="cm"> * Represents workshop where different works with cars, boats</span>
</span><span class='line'><span class="cm"> * and other vehicles can be done.</span>
</span><span class='line'><span class="cm"> *</span>
</span><span class='line'><span class="cm"> * @author Dmitry Churbanov</span>
</span><span class='line'><span class="cm"> */</span>
</span><span class='line'><span class="kd">public</span> <span class="kd">class</span> <span class="nc">Workshop</span> <span class="o">{</span>
</span><span class='line'>  <span class="kd">public</span> <span class="kd">static</span> <span class="kt">void</span> <span class="nf">main</span><span class="o">(</span><span class="n">String</span><span class="o">[]</span> <span class="n">args</span><span class="o">)</span> <span class="o">{</span>
</span><span class='line'>    <span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="s">&quot;Welcome to our Workshop!&quot;</span><span class="o">);</span>
</span><span class='line'>  <span class="o">}</span>
</span><span class='line'><span class="o">}</span>
</span></code></pre></td></tr></table></div></figure>




<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
</pre></td><td class='code'><pre><code class='java'><span class='line'><span class="kn">package</span> <span class="n">com</span><span class="o">.</span><span class="na">churbanov</span><span class="o">.</span><span class="na">tutorial</span><span class="o">.</span><span class="na">egit</span><span class="o">;</span>
</span><span class='line'>
</span><span class='line'><span class="kd">public</span> <span class="kd">class</span> <span class="nc">Part</span> <span class="o">{</span>
</span><span class='line'>  <span class="kd">private</span> <span class="n">Long</span> <span class="n">id</span><span class="o">;</span>
</span><span class='line'>  <span class="kd">private</span> <span class="n">String</span> <span class="n">name</span><span class="o">;</span>
</span><span class='line'>
</span><span class='line'>  <span class="kd">public</span> <span class="n">Long</span> <span class="nf">getId</span><span class="o">()</span> <span class="o">{</span>
</span><span class='line'>    <span class="k">return</span> <span class="n">id</span><span class="o">;</span>
</span><span class='line'>  <span class="o">}</span>
</span><span class='line'>  <span class="kd">public</span> <span class="kt">void</span> <span class="nf">setId</span><span class="o">(</span><span class="n">Long</span> <span class="n">id</span><span class="o">)</span> <span class="o">{</span>
</span><span class='line'>    <span class="k">this</span><span class="o">.</span><span class="na">id</span> <span class="o">=</span> <span class="n">id</span><span class="o">;</span>
</span><span class='line'>  <span class="o">}</span>
</span><span class='line'>  <span class="kd">public</span> <span class="n">String</span> <span class="nf">getName</span><span class="o">()</span> <span class="o">{</span>
</span><span class='line'>    <span class="k">return</span> <span class="n">name</span><span class="o">;</span>
</span><span class='line'>  <span class="o">}</span>
</span><span class='line'>  <span class="kd">public</span> <span class="kt">void</span> <span class="nf">setName</span><span class="o">(</span><span class="n">String</span> <span class="n">name</span><span class="o">)</span> <span class="o">{</span>
</span><span class='line'>    <span class="k">this</span><span class="o">.</span><span class="na">name</span> <span class="o">=</span> <span class="n">name</span><span class="o">;</span>
</span><span class='line'>  <span class="o">}</span>
</span><span class='line'><span class="o">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>Now we need to tell Git to start tracking just added classes. To do so, we select Part.java and Workshop.java classes in
eclipse package explorer -> Team -> Add</p>

<p><img class="center" src="http://www.churbanov.com/blog/images/2010-08-11-eclipse-egit-plugin-part-2/add-files.jpeg"></p>

<h3>Commit changes</h3>

<p>To commit changes select Team -> Commit. The “Commit Changes” window will pop up and you will need to enter commit
message and select what files you want to commit or unselect the files you don’t want to commit. Press “Commit” and all
the changes will be committed.</p>

<p><img class="center" src="http://www.churbanov.com/blog/images/2010-08-11-eclipse-egit-plugin-part-2/commit-changes.jpeg"></p>

<p>After commit you can see that Workshop.java and Part.java files icons are changed in package explorer.</p>

<p><img class="center" src="http://www.churbanov.com/blog/images/2010-08-11-eclipse-egit-plugin-part-2/part-workshop-classes.jpeg"></p>

<h3>Push changes</h3>

<p>To push the changes to the remote repository select Team -> Push. The current version of EGit (0.8.4) has a bug and in
most cases push will not work (more is <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=317389">here</a>). There is a small
workaround (see <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=317389#c2">Comment #2</a> in that bug discussion), but it
still didn’t work for me on my Ubuntu 10.04. So I did it in command line. (Just after I had published this post I found
that EGit doesn’t support pushing via https. More is <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=296201">here</a>.)</p>

<h2>Other useful things</h2>

<p>The other useful things which you can do with EGit are:</p>

<h3>Tags</h3>

<p>Select “eclipse_git” project folder -> Team -> Tag. Enter tag name, tag message and press OK button.</p>

<p><img class="center" src="http://www.churbanov.com/blog/images/2010-08-11-eclipse-egit-plugin-part-2/tag.jpeg"></p>

<h3>History of a particular resource</h3>

<p>Select any resource (project, package, class, etc) -> Show In -> History. And you can see all the history of the selected resource in the Git repository.</p>

<p><img class="center" src="http://www.churbanov.com/blog/images/2010-08-11-eclipse-egit-plugin-part-2/history-menu.jpeg"></p>

<p><img class="center" src="http://www.churbanov.com/blog/images/2010-08-11-eclipse-egit-plugin-part-2/history.jpeg"></p>

<h3>Branches</h3>

<p>If you want to make a branch, select “eclipse_git” project folder -> Team -> Branch.</p>

<p><img class="center" src="http://www.churbanov.com/blog/images/2010-08-11-eclipse-egit-plugin-part-2/branch.jpeg"></p>

<p>In the appeared window select “master” in the “Local Branches” category -> press “New branch” button -> enter new branch name -> press OK button. New branch will be created.</p>

<p><img class="center" src="http://www.churbanov.com/blog/images/2010-08-11-eclipse-egit-plugin-part-2/creating-new-branch.jpeg"></p>

<p>To switch to the new branch select “eclipse_egit” project folder -> Team -> Branch -> select the branch you want to switch to -> press Checkout button.</p>

<p><img class="center" src="http://www.churbanov.com/blog/images/2010-08-11-eclipse-egit-plugin-part-2/switching-to-new-branch.jpeg"></p>

<h2>Useful links</h2>

<ul>
<li>Using Git: <a href="http://www.churbanov.com/blog/2010/07/08/using-git-part-1/">http://www.churbanov.com/blog/2010/07/08/using-git-part-1/</a></li>
<li>Eclipse EGit plugin: <a href="http://www.churbanov.com/blog/2010/07/12/eclipse-egit-plugin/">http://www.churbanov.com/blog/2010/07/12/eclipse-egit-plugin/</a></li>
<li>EGit user guide: <a href="http://wiki.eclipse.org/EGit/User_Guide">http://wiki.eclipse.org/EGit/User_Guide</a></li>
<li>Git community book: <a href="http://book.git-scm.com/">http://book.git-scm.com/</a></li>
<li>Git reference site: <a href="http://gitref.org/index.html">http://gitref.org/index.html</a></li>
</ul>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Eclipse EGit plugin]]></title>
    <link href="http://www.churbanov.com/blog/2010/07/12/eclipse-egit-plugin/"/>
    <updated>2010-07-12T20:00:00-07:00</updated>
    <id>http://www.churbanov.com/blog/2010/07/12/eclipse-egit-plugin</id>
    <content type="html"><![CDATA[


<p><img class="left" src="http://www.churbanov.com/blog/images/2010-07-12-eclipse-egit-plugin/egit.png" width="150" height="149">
<a href="http://www.eclipse.org/downloads/">Eclipse Helios</a> (ver. 3.6) is out and
<a href="http://eclipsesource.com/blogs/2010/06/22/git-support-eclipse-helios-feature-2/">the second top requested feature</a> was Git
support. And here it is: <a href="http://www.eclipse.org/egit/">EGit plug-in</a>. It is still in the
“<a href="http://wiki.eclipse.org/Development_Resources/HOWTO/Incubation_Phase">Incubation Phase</a>“, but you already can try it.</p>

<p>In this tutorial I will show the basic steps of creating Java project in eclipse using EGit plug-in. Eclipse “Helios” and EGit
version 0.8.4 are used in this tutorial.</p>

<h2>Install EGit plugin</h2>

<p>Start eclipse. Go to Help -> Install New Software…
In the “Work with” select “All Available Sites”. And then in the search box enter git. You will see the following picture:</p>

<p><img class="center" src="http://www.churbanov.com/blog/images/2010-07-12-eclipse-egit-plugin/1-Searching_egit_plugin.jpeg"></p>

<p>Select “Eclipse EGit (Incubation)”:</p>

<p><img class="center" src="http://www.churbanov.com/blog/images/2010-07-12-eclipse-egit-plugin/2-Selecting_egit_plugin_to_install.jpeg"></p>

<p>Click Next. Eclipse JGit plugin will be installed automatically as a dependency of EGit plugin:</p>

<p><img class="center" src="http://www.churbanov.com/blog/images/2010-07-12-eclipse-egit-plugin/5-EGit_plugin_installation_details.jpeg"></p>

<p>Press “Next”, accept the terms of the licence agreement:</p>

<p><img class="center" src="http://www.churbanov.com/blog/images/2010-07-12-eclipse-egit-plugin/6-Accepting_license_agreement.jpeg"></p>

<p>press Finish and after some time plugins will be installed. Restart eclipse.</p>

<h2>Import Git repository and create new project</h2>

<p>After eclipse is restarted select File -> Import…, and you will see the new category: Git. Expand it and select
“Projects from Git”. Press next.</p>

<p><img class="center" src="http://www.churbanov.com/blog/images/2010-07-12-eclipse-egit-plugin/10-Import_projects_from_git.jpeg"></p>

<p>The next window will ask you about Git repository location. You can see two buttons there: Clone and Add. Add button should be
used when you already have a local copy of Git repository. If you don’t have such copy, you need to press Clone button.</p>

<p><img class="center" src="http://www.churbanov.com/blog/images/2010-07-12-eclipse-egit-plugin/9-Selecting_git_repository.jpeg"></p>

<p>In this tutorial we will import remote Git repository, i.e. at this moment we do not have a local copy of this repository on our
hard drive. The Git repository which we are going to import has been already created on <a href="http://github.com/">github</a>.</p>

<p>So, press Clone button and enter all location parameters. If you go to the github project properties, you can select what protocol
are you going to use. I have selected https. Here is an example (if you just copy and past url from github to URI field all other
fields, except password, should be filled out automatically):</p>

<p><img class="center" src="http://www.churbanov.com/blog/images/2010-07-12-eclipse-egit-plugin/11-Git_repository_parameters.jpeg"></p>

<p>If all parameters are correct, after pressing Next button you will see the branch selection window. In my case I do not have any
branches, therefore I just press Next and select where the local copy of the Git repository will be stored. And here is the
problem. You should save the copy of your Git repository in the same folder where you plan to create eclipse project. If you save
Git repository in another folder, you will not be able to “share” your project with that repository. There is a solution which
solves this problem, but we will talk about it later.</p>

<p><img class="center" src="http://www.churbanov.com/blog/images/2010-07-12-eclipse-egit-plugin/13-Git_local_path.jpeg"></p>

<p>After that select just added Git repository and press Next button:</p>

<p><img class="center" src="http://www.churbanov.com/blog/images/2010-07-12-eclipse-egit-plugin/14-Selecting_git_repository.jpeg"></p>

<p>and “Import Projects from Git” window will appear. As we are going to create new project select “Use the New Projects wizard” and
press Finish.</p>

<p><img class="center" src="http://www.churbanov.com/blog/images/2010-07-12-eclipse-egit-plugin/16-Sharing_the_imported_project.jpeg"></p>

<p>Now we will create new Java Project using default parameters:</p>

<p><img class="center" src="http://www.churbanov.com/blog/images/2010-07-12-eclipse-egit-plugin/17-Creating_Java_project.jpeg"></p>

<p><img class="center" src="http://www.churbanov.com/blog/images/2010-07-12-eclipse-egit-plugin/18-Project_settings.jpeg"></p>

<p>and here it is:</p>

<p><img class="center" src="http://www.churbanov.com/blog/images/2010-07-12-eclipse-egit-plugin/19-Java_project_with_Git_repository.jpeg"></p>

<p>We can see the name of eclipse project (“eclipse_git”), name of Git repository (“eclipse_git”) and repository branch (“master”).</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Using Git, part 1]]></title>
    <link href="http://www.churbanov.com/blog/2010/07/08/using-git-part-1/"/>
    <updated>2010-07-08T20:00:00-07:00</updated>
    <id>http://www.churbanov.com/blog/2010/07/08/using-git-part-1</id>
    <content type="html"><![CDATA[


<p><a href="http://git-scm.com/">Git</a> is a Distributed Version Control System (DVCS) (as Mercurial
<a href="http://www.churbanov.com/blog/2009/12/29/working-with-mercurial-part-1/">about which I wrote earlier</a>).
As well as Mercurial, Git mirrors your repository: every time when you check out code you make a full copy of a repository.
Almost all hosting web sites provide you with a possibility to use Git. One of the most widely used Git hosting web sites is
<a href="http://github.com/">github</a>. There is one very good book about Git: <a href="http://progit.org/book">Pro Git</a>. You can read it online.
This is my reference book and I advise everybody to read it.</p>

<h2>Let’s start – Configuration</h2>

<p>Git comes with a git config tool. It helps you to set and get configuration parameters and control all aspects of Git.
All configuration parameters can be found at three places:</p>

<ul>
<li><code>/etc/gitconfig</code> – contains global parameters for all users of your system. Gets and sets parameters if you pass
<code>--system option</code> to git config.</li>
<li><code>~/.gitconfig</code> – contains parameters specific to current user. Works if you pass <code>--global</code> option to git config.</li>
<li><code>.git/config</code> – contains parameters specifically for the git repository you are currently using. Don’t need to pass any
parameters when using git config. Works by default.</li>
</ul>


<p>All parameter values overwrite values on other levels, i.e. if some value for some parameter is specified in <code>/etc/gitconfig</code>
file and another value for the same parameter is specified in <code>~/.gitconfig</code> file, the value from the last file will be used.
The same works for values in <code>~/.gitconfig</code> and <code>.git/config</code> files. In that case the value from <code>.git/config</code> file will be used.</p>

<p>First things which you need to do is to define your identity:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>git config --global user.name <span class="s2">&quot;Dmitry Churbanov&quot;</span>
</span><span class='line'><span class="nv">$ </span>git config --global user.email dmitry.churbanov@someemail.com
</span></code></pre></td></tr></table></div></figure>


<p>that code will assign git user name and email address for current user of a system. If you want to set up user name and email
just for current project which you are working on right now you need to run the following code:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>git config user.name <span class="s2">&quot;Dmitry Churbanov&quot;</span>
</span><span class='line'><span class="nv">$ </span>git config user.email dmitry.churbanov@someemail.com
</span></code></pre></td></tr></table></div></figure>


<p>If you want to check the value of any parameter you need to run the next code:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>git config parameter-name
</span></code></pre></td></tr></table></div></figure>


<p>where <code>parameter-name</code> is the name of a parameter. For example, to see the name of a user or email you can check it in the
following way:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>git config user.name
</span><span class='line'>Dmitry Churbanov
</span><span class='line'><span class="nv">$ </span>git config user.email
</span><span class='line'>dmitry.churbanov@someemail.com
</span></code></pre></td></tr></table></div></figure>


<h2>Initialise repository</h2>

<p>To initialise git repository go to the directory where you want the repository to be placed and run:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>git init
</span></code></pre></td></tr></table></div></figure>


<p>After this command is executed you will see <code>.git</code> subdirectory which contains all the repository files. This is the only
repository where Git stores its configuration files and the history of all changes.</p>

<h2>Add files</h2>

<p>After you initialised the repository it does not contain any files. To tell Git to start tracking a file you first need to
create it in the directory or to copy it to the directory and run:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>git add filename
</span></code></pre></td></tr></table></div></figure>


<p>where <code>filename</code> is a name of a file to start to track. You can also run:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>git add .
</span></code></pre></td></tr></table></div></figure>


<p>and Git will start to track all the files in the current directory and all the subdirectories which it doesn’t track at this
moment. You can also use some kind of regular expression. If you want to add only .java files you need to run the following
command:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>git add *.java
</span></code></pre></td></tr></table></div></figure>


<h2>Committing files and file states</h2>

<p>After you added some files you told Git that you want to start to keep track these files in the future, i.e. you want to include
these files in your next commit command. This state of files in the Git repository is called: <strong>staged</strong>.
After you added all the files and are ready to make commit you need to run:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>git commit -m <span class="s2">&quot;commit message&quot;</span>
</span></code></pre></td></tr></table></div></figure>


<p>where <code>commit message</code> is a message which goes with this commit and should describe the purpose of the commit. For example, when
you fixed a bug and commit you changes you most probably will include some information which describes what bug it is or its
number or something else.</p>

<p>If you just run <code>git commit</code> (or <code>git commit -a</code>) command you then will be asked to write “commit message”. It is recommended to
run commit command without <code>-m</code> flag if your message is longer than one line. And in most cases it will and should be longer
and detailed.</p>

<p>After you made commit, all files which were committed got a <strong>committed</strong> state. If file was committed and them modified, it got
a <strong>modified</strong> state. So, there are three states which tracked files can have:</p>

<ul>
<li>staged – when you told to include the file in the next commit (run add command)</li>
<li>commit – when file was committed and was not changed after this</li>
<li>modified – when file was committed and was changed after this</li>
</ul>


<p>I wrote <strong>tracked</strong> earlier to point out that these are the files which Git is tracking. If file is not tracked by Git, it is
called untracked. Untracked files are all files which are not tracked.</p>

<h2>Status of the files</h2>

<p>To check status of all files and to find their states, you need to run:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>git status
</span><span class='line'><span class="c"># On branch master</span>
</span><span class='line'><span class="c"># Your branch is ahead of &#39;origin/master&#39; by 1 commit.</span>
</span><span class='line'><span class="c">#</span>
</span><span class='line'>nothing to commit <span class="o">(</span>working directory clean<span class="o">)</span>
</span></code></pre></td></tr></table></div></figure>


<p>You can see something like you see above. It means that I made commit and didn’t push my changes (<code>push</code> command is discussed
later). Or you can see:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>git status
</span><span class='line'><span class="c"># On branch master</span>
</span><span class='line'>nothing to commit <span class="o">(</span>working directory clean<span class="o">)</span>
</span></code></pre></td></tr></table></div></figure>


<p>which means that your local (working) copy is in the same state as a remote repository.</p>

<h2>Ignoring files</h2>

<p>Sometimes you don’t want to include some files in the repository but you still want these files to be present in the folder.
This can be some of your personal files, logs or anything else. You can say Git to ignore these files. To do so you need to
create <code>.gitignore</code> file and write file names or file name patters there.</p>

<p>For example, if you want to say Git to ignore all .txt files you need to have the following in the <code>.gitignore</code> file:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>*.txt
</span></code></pre></td></tr></table></div></figure>


<p>If some file matches the regular expression which is in the ignore file but you want to tell Git to keep track that particular
file, you can do it in the next way:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="c">#Text files should be ignored (this is a comment, which is ignored in the .gitignore file)</span>
</span><span class='line'>*.txt
</span><span class='line'>!important.txt
</span></code></pre></td></tr></table></div></figure>


<p>In such case <code>important.txt</code> file will be tracked by Git, even if all .txt files are ignored.</p>

<h2>Diff command</h2>

<p>When changes are made and <code>git status</code> command is executed, you can be wondered, what exactly is changed in the files which are
modified. You can use <code>git diff</code> command. This command shows you what changes have been made. The following command:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>git diff <span class="o">[</span>path<span class="o">]</span>
</span></code></pre></td></tr></table></div></figure>


<p>will show you what changes have been made in a specific file, if instead of path you write path to the file; or what changes have
been made in all files of a specific folder if instead of path you write path to that folder. To see all options of diff command
run <code>git diff --help</code>.</p>

<p><strong>One very important note:</strong>
If you have already added a file, say <code>file1.txt</code>, by running <code>git add file1.txt</code> command. And after that you made some changes
in that file, then if you run <code>git diff file1.txt</code> you will not see the latest changes. It is because after you run
<code>git add file1.txt</code> Git cached the context of <code>file1.txt</code> file at that moment. To see cached changes you need to run:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>git diff --cached <span class="o">[</span>path<span class="o">]</span>
</span></code></pre></td></tr></table></div></figure>


<p>And if you run <code>git commit</code> your latest changes will also not be committed. To add the latest changes you need to run <code>git add</code>
after each modification. But there is one trick. You can use <code>-a</code> option with the <code>git commit</code> command to commit all files which
were previously tracked and were modified. It allows you to skip <code>git add</code> every time you make any change and run it only once.</p>

<h2>Removing files</h2>

<p>If you want to remove file, i.e. to remove it from the repository (and remove it from your hard drive) you need to run:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>git rm <span class="o">[</span>path<span class="o">]</span>
</span></code></pre></td></tr></table></div></figure>


<p>This command tells Git to remove file. After the next commit command this file will be removed from the repository. But if you
want to leave file on your hard drive and only stop to keep tracking that file, you need to run:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>git rm --cached readme.txt
</span></code></pre></td></tr></table></div></figure>


<h2>Moving files</h2>

<p>To move file or rename it you need to run the following command:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>git mv <span class="o">[</span>file-name<span class="o">]</span> <span class="o">[</span>new-file-name<span class="o">]</span>
</span></code></pre></td></tr></table></div></figure>


<p>But it is very interesting that Git doesn’t actually track if you moved your file or not. It is somehow explicitly figures out
that you renamed the file after you run something like this:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>mv file.txt new_file.txt
</span><span class='line'><span class="nv">$ </span>git rm file.txt
</span><span class='line'><span class="nv">$ </span>git add new_file.txt
</span></code></pre></td></tr></table></div></figure>


<p>Try to run <code>git status</code> and see what happens. It is very convenient because you can rename or move file using whatever tool or
program you want and them just remove and add it using Git <code>rm</code> and <code>add</code> commands.</p>

<h2>Help</h2>

<p>If you need help with any command use <code>git help [command]</code> or <code>git [command] --help</code>. For example, to get help with commit
command you need to run:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>git <span class="nb">help </span>commit
</span></code></pre></td></tr></table></div></figure>


<p>This is it for the first post in the “Using Git” series. I think you have read pretty enough material to start using Git.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Working with Mercurial, part 1]]></title>
    <link href="http://www.churbanov.com/blog/2009/12/29/working-with-mercurial-part-1/"/>
    <updated>2009-12-29T20:00:00-08:00</updated>
    <id>http://www.churbanov.com/blog/2009/12/29/working-with-mercurial-part-1</id>
    <content type="html"><![CDATA[


<p><img class="left" src="http://www.churbanov.com/blog/images/2009-12-29-working-with-mercurial-part-1/Mercurial_logo_140_168.png" width="140" height="168">
<a href="http://mercurial.selenic.com/">Mercurial</a> is a <a href="http://en.wikipedia.org/wiki/Distributed_revision_control">distributed revision control</a> (DRC) management system.
Decentralization is one of its advantages. For an individual developer DRC systems are faster than centralized:
all metadata is stored locally and you don&#8217;t need to contact the central server each time you modified the code.</p>

<p>Mercurial repository is self-contained. It means that all changes you have made will exist only in your local
repository until you decide to propagate these changes to the remote one.</p>

<p>This series of posts is how to start working with Mercurial. If you are looking for a book, there is a very good
one which is publicly available: <a href="http://hgbook.red-bean.com/read/">Mercurial: The Definitive Guide by by Bryan O’Sullivan</a>. And I advise you to read it.</p>

<h2>In the beginning</h2>

<p>All Mercurial commands starts from <code>hg</code>. The <code>hg</code> command provides a command line interface to the Mercurial system. In general each command has the following syntax:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>hg <span class="nb">command</span> <span class="o">[</span>options<span class="o">]</span>...<span class="o">[</span>arguments<span class="o">]</span>...
</span></code></pre></td></tr></table></div></figure>


<h2>Setting up a new Mercurial project</h2>

<p>Let’s say you want to create a local repository named <strong>repository-main</strong>:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>mkdir repository-main
</span><span class='line'><span class="nv">$ </span><span class="nb">cd </span>repository-main
</span><span class='line'><span class="nv">$ </span>hg init
</span></code></pre></td></tr></table></div></figure>


<p><code>init</code> command initializes new repository in the current folder.
Here is a more shorter way of creating the local repository:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>hg init repository-main
</span></code></pre></td></tr></table></div></figure>


<p>If you check <strong>repository-main</strong> folder you can see <strong>.hg</strong> folder there.</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>ls -la
</span><span class='line'><span class="nv">$ </span>.
</span><span class='line'><span class="nv">$ </span>..
</span><span class='line'><span class="nv">$ </span>.hg
</span></code></pre></td></tr></table></div></figure>


<p><strong>.hg</strong> folder is the only folder where Mercurial keeps all repository related information.</p>

<p>But hardly ever you will create repository on you local computer. Most probably you will use one of the many hosting services
to host your repository there. One of the lists of such places you can find <a href="http://mercurial.selenic.com/wiki/MercurialHosting">here</a>.</p>

<h2>Working with existing Mercurial repository</h2>

<p>Let’s assume you are using one of the services to host your Mercurial repository (for this post I have used <a href="http://kenai.com/">Project Kenai</a>).
To clone files from remote repository and create a local copy on your machine use <code>clone</code> command:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>hg clone ssh://dzmitryc@hg.kenai.com/project-test1~source-code-repository project-test1
</span><span class='line'>no changes found
</span><span class='line'>updating working directory
</span><span class='line'>0 files updated, 0 files merged, 0 files removed, 0 files unresolved
</span></code></pre></td></tr></table></div></figure>


<p><code>clone</code> command created new directory <strong>project-test1</strong> and checked out the latest version of the default branch. In Mercurial,
the newest version of the branch is called <strong>tip</strong>. To see the logs about the newest version of the repository you can execute the <code>tip</code> command:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span><span class="nb">cd </span>project-test1
</span><span class='line'><span class="nv">$ </span>hg tip
</span><span class='line'>changeset:   -1:000000000000
</span><span class='line'>tag:         tip
</span><span class='line'>user:
</span><span class='line'>date:        Thu Jan 01 00:00:00 1970 +0000
</span></code></pre></td></tr></table></div></figure>


<p>As our repository is new and empty we don’t see much info.</p>

<h2>What about adding new files?</h2>

<p>Now lets create the file <code>HelloWorld.java</code> with the following content:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class='java'><span class='line'><span class="kd">public</span> <span class="kd">class</span> <span class="nc">HelloWorld</span> <span class="o">{</span>
</span><span class='line'>  <span class="kd">public</span> <span class="kd">static</span> <span class="kt">void</span> <span class="nf">main</span><span class="o">(</span><span class="n">String</span> <span class="n">args</span><span class="o">[])</span> <span class="o">{</span>
</span><span class='line'>    <span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="s">&quot;Hello World!&quot;</span><span class="o">);</span>
</span><span class='line'>  <span class="o">}</span>
</span><span class='line'><span class="o">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>We have the next in our folder <strong>project-test1</strong>:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>ls -la
</span><span class='line'><span class="nv">$ </span>.
</span><span class='line'><span class="nv">$ </span>..
</span><span class='line'><span class="nv">$ </span>HelloWorld.java
</span><span class='line'><span class="nv">$ </span>.hg
</span></code></pre></td></tr></table></div></figure>


<p>If we run <code>hg status</code> command we’ll see the following:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>hg status
</span><span class='line'>? HelloWorld.java
</span></code></pre></td></tr></table></div></figure>


<p>The <code>status</code> command shows the status of files in the repository. In our case we can see <code>?</code> (question mark) before the <code>HelloWorld.java</code> file.
It means that this file is not tracked by Mercurial. The next codes are used to show the status:</p>

<ul>
<li>M = modified</li>
<li>A = added</li>
<li>R = removed</li>
<li>C = clean</li>
<li>! = missing (deleted by non-hg command, but still tracked)</li>
<li>? = not tracked</li>
<li>I = ignored</li>
</ul>


<p>Now if you want to tell Mercurial to start to track the file and add it to the repository you need to execute <code>hg add</code> command:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>hg add HelloWorld.java
</span></code></pre></td></tr></table></div></figure>


<p>You can check that Mercurial is tracking just added file by executing <code>hg status</code> command:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>hg status
</span><span class='line'>A HelloWorld.java
</span></code></pre></td></tr></table></div></figure>


<h2>Committing changes</h2>

<p>To commit the changes you need to execute <code>hg commit</code> command:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>hg commit
</span></code></pre></td></tr></table></div></figure>


<p>Just after you press <em>Enter</em> button Mercurial will run a text editor and ask you to write a comment:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>_
</span><span class='line'>
</span><span class='line'>HG: Enter commit message.  Lines beginning with <span class="s1">&#39;HG:&#39;</span> are removed.
</span><span class='line'>HG: Leave message empty to abort commit.
</span><span class='line'>HG: --
</span><span class='line'>HG: user: dmitry@dmitry-laptop
</span><span class='line'>HG: branch <span class="s1">&#39;default&#39;</span>
</span><span class='line'>HG: added HelloWorld.java
</span></code></pre></td></tr></table></div></figure>


<p>Lines started with HG will be removed. It is better to wright a good and clear comment so later you can find out what was the purpose of the commit.
In our case we can wright something like: “Add new file HelloWorld.java”.</p>

<p>Another way of committing is to execute:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>hg commit -m <span class="s1">&#39;Commit message&#39;</span>
</span></code></pre></td></tr></table></div></figure>


<p>where instead of ‘Commit message’ text you can write your commit comment.</p>

<p>Now if you execute <code>hg status</code> command you see nothing. It is because status command only shows files with which something needs to be done.
Files which have already been tracked and were not changed will not be shown. After executing <code>hg commit</code> command all changes will be saved
in your local repository.</p>

<h2>Moving changes to the remote repository</h2>

<p>As it has been said, each local repository is a full copy of a working repository. And if you make any changes in a local repository and make
commit, changes are not automatically propagated to the working repository until you decide to do so.</p>

<p>Let’s say you are fixing bugs. And every day you are fixing only one bug. And after the work was done you commit your changes to the local
repository. But at the end of each week you decide to move all your changes from your local repository to the working one. To do so you need
to execute <code>hg push</code> command:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>hg push
</span><span class='line'>pushing to ssh://dzmitryc@hg.kenai.com/project-test1~source-code-repository
</span><span class='line'>searching <span class="k">for </span>changes
</span><span class='line'>remote: adding changesets
</span><span class='line'>remote: adding manifests
</span><span class='line'>remote: adding file changes
</span><span class='line'>remote: added 1 changesets with 1 changes to 1 files
</span></code></pre></td></tr></table></div></figure>


<p>Our changes were pushed to the remote repository and new changeset was created.</p>
]]></content>
  </entry>
  
</feed>
