<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href="https://basetta.bz/feed_style.xsl" type="text/xsl"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <tabi:metadata xmlns:tabi="https://github.com/welpo/tabi">
        <tabi:base_url>https://basetta.bz</tabi:base_url>
        <tabi:separator>
            •
        </tabi:separator>
        <tabi:about_feeds>
            This is a web feed, also known as an Atom feed. Subscribe by copying the URL from the address bar into your newsreader. Visit About Feeds to learn more and get started. It's free.
        </tabi:about_feeds>
        <tabi:visit_the_site>
            Visit website
        </tabi:visit_the_site>
        <tabi:recent_posts>
            Recent posts
        </tabi:recent_posts>
        <tabi:last_updated_on>
            Updated on $DATE
        </tabi:last_updated_on>
        <tabi:default_theme></tabi:default_theme>
        <tabi:post_listing_date>date</tabi:post_listing_date>
        <tabi:current_section>git</tabi:current_section>
    </tabi:metadata><title>Basetta&apos;s Website - git</title>
        <subtitle>Welcome to my personal blog! Find honest reflections, helpful advice, and a fresh perspective on travel, lifestyle, and more. Start exploring now.</subtitle>
    <link href="https://basetta.bz/tags/git/atom.xml" rel="self" type="application/atom+xml"/>
    <link href="https://basetta.bz/tags/git/" rel="alternate" type="text/html"/>
    <generator uri="https://www.getzola.org/">Zola</generator><updated>2020-03-27T00:00:00+00:00</updated><id>https://basetta.bz/tags/git/atom.xml</id><entry xml:lang="en">
        <title>How to recover a deleted file in Git</title>
        <published>2020-03-27T00:00:00+00:00</published>
        <updated>2020-03-27T00:00:00+00:00</updated>
        <author>
            <name>Patrick Martini</name>
        </author>
        <link rel="alternate" href="https://basetta.bz/blog/how-to-recover-a-deleted-a-file-in-git/" type="text/html"/>
        <id>https://basetta.bz/blog/how-to-recover-a-deleted-a-file-in-git/</id>
        
            <content type="html">&lt;span id=&quot;continue-reading&quot;&gt;&lt;/span&gt;
&lt;p&gt;At work happens multiple times that I got asked how to recover a file somebody else deleted from a git repository.&lt;/p&gt;
&lt;p&gt;Even if it is not complicated, I decided to jot down a quick tutorial for future reference.
The process takes 3 steps:
find all deleted files&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$ git log --diff-filter=D --summary | grep delete&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;find the file you are looking for&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$ git log -- &amp;lt;filename&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;find the last commit before the file was deleted&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;git rev-list -n 1 HEAD -- &amp;lt;filename&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;restore the file&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;git checkout ~&amp;lt;commit&amp;gt; -- &amp;lt;filename&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Restore the file!
That is it. Your deleted file has been recovered.&lt;/p&gt;
</content>
        </entry><entry xml:lang="en">
        <title>Protect Your Private Data Using Gitconfig Include Directive</title>
        <published>2013-01-28T00:00:00+00:00</published>
        <updated>2013-01-28T00:00:00+00:00</updated>
        <author>
            <name>Patrick Martini</name>
        </author>
        <link rel="alternate" href="https://basetta.bz/blog/protect-your-private-data-using-gitconfig-include-directive/" type="text/html"/>
        <id>https://basetta.bz/blog/protect-your-private-data-using-gitconfig-include-directive/</id>
        
            <content type="html">&lt;span id=&quot;continue-reading&quot;&gt;&lt;/span&gt;
&lt;p&gt;I am using a &lt;a rel=&quot;external&quot; href=&quot;https://github.com/basetta/dotfiles&quot;&gt;dotfiles&lt;/a&gt; git repository in order to keep my machine preferences in sync.&lt;/p&gt;
&lt;p&gt;This is working pretty well, until you realise that are some config entries that are clashing with each other.&lt;/p&gt;
&lt;p&gt;One of those cases, is the common situation  of having two github accounts – one for work and one for private purposes. In this case we would like to share the common git configuration but not the committer’s author name and email address held in the .gitconfig.&lt;/p&gt;
&lt;p&gt;Recently, git added a new feature, the include directive for config files ( since 1.7.10 ) that can solve the problem.
With the include feature you can split your gitconfig across multiple files, so you can have the common git configuration in one file, and private information in another.&lt;/p&gt;
&lt;p&gt;Let’s have a look at an example :&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Add the include directive to your .gitconfig ( this is the file in your git dotfiles repository )&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[include]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;path = ~/.gitconfig_user&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;Add to ~/.gitconfig_user your private data&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[user]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;name = Silvio Berlusconi&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;email = silvio.berlusconi@bungabunga.it&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;Test if the config is working properly&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$ git config user.name&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Silvio Berlusconi&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$ git config user.email&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;silvio.berlusconi@bungabunga.it&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;</content>
        </entry><entry xml:lang="en">
        <title>Extract a Directory From a Git Branch/Repository Preserving The History</title>
        <published>2012-05-12T00:00:00+00:00</published>
        <updated>2012-05-12T00:00:00+00:00</updated>
        <author>
            <name>Patrick Martini</name>
        </author>
        <link rel="alternate" href="https://basetta.bz/blog/extract-a-directory-from-a-git-branch-slash-repository-preserving-the-history/" type="text/html"/>
        <id>https://basetta.bz/blog/extract-a-directory-from-a-git-branch-slash-repository-preserving-the-history/</id>
        
            <content type="html">&lt;span id=&quot;continue-reading&quot;&gt;&lt;/span&gt;
&lt;p&gt;At work we wanted to extract from a branch a subdirectory containing a specific feature that had to be used from everyone in the team.
Just for sake of example, let’s define the terms of our problem.
Our repository (MAIN) structure looks like:&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;MAIN/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        Library/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            libA/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            libB/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            libC/&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Our goal is to extract the libA contained in the branch FTR-B in its own branch called FTR-A.&lt;/p&gt;
&lt;p&gt;If you are not interested in preserving the history the task is quite easy. &lt;strong&gt;Git checkout&lt;/strong&gt; is our friend in this case.&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$ git checkout master&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$ git checkout -b FTR-A&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$ git checkout FTR-B Library/libA&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$ git commit -a -m &amp;quot;Extract libA&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$ git push&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;More complicated is the case in which preserving the history is a matter of importance.
For God’s sake &lt;strong&gt;git&lt;/strong&gt; has a powerful command &lt;strong&gt;git filter-branch&lt;/strong&gt;.
The following are my notes and observations, for pleasing my poor memory.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Clone the local repository into a temporary repository DIRTY.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$ git clone ~/MAIN/ ~/DIRTY/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$ cd DIRTY&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$ git checkout FTR-B&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;Remove everything except the desired subdirectory ( libA ).&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$ git filter-branch --prune-empty --tree-filter &amp;#39;rm -rf Library/libB Library/libC&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Basically, &lt;strong&gt;Git filter-branch&lt;/strong&gt; executes a command on each commit in a specific branch. Instead of the option &lt;strong&gt;tree-filter&lt;/strong&gt; you could have used &lt;strong&gt;subdirectory-filter&lt;/strong&gt; that removes everything except the desired directory moving it up to the root project. I will explain it better in another post.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Clean all the cruft&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$ git gc --aggressive&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;Merge the new feature in its own branch FTR-A.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$ cd ~/MAIN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$ git remote add dirty ~/DIRTY&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$ git fetch dirty&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$ git branch dirty remotes/tools/FTR-B&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$ git checkout master&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$ git checkout -b FTR-A&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$ git merge dirty&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$ git remote rm dirty&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;Create a pull request&lt;/li&gt;
&lt;/ul&gt;
</content>
        </entry><entry xml:lang="en">
        <title>How to fetch upstream changes in git easily</title>
        <published>2012-04-18T00:00:00+00:00</published>
        <updated>2012-04-18T00:00:00+00:00</updated>
        <author>
            <name>Patrick Martini</name>
        </author>
        <link rel="alternate" href="https://basetta.bz/blog/how-to-fetch-upstream-changes-in-git-easily/" type="text/html"/>
        <id>https://basetta.bz/blog/how-to-fetch-upstream-changes-in-git-easily/</id>
        
            <content type="html">&lt;p&gt;It is quite common to update your git fork repository with the upstream changes.&lt;/p&gt;
&lt;p&gt;Here it is the workflow I use to keep synchronize my branch with &lt;a rel=&quot;external&quot; href=&quot;http://www.google.com&quot;&gt;Octopress&lt;/a&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;First of all, we should configure the remotes.&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-3 z-i&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;z-7&quot;&gt; git remote add upstream git://github.com/imathis/octopress.git&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Check the remotes&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-3 z-i&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;z-7&quot;&gt; git remote&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Merge/Rebase the changes&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-3 z-i&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;z-7&quot;&gt; git fetch origin -v&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-3 z-i&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;z-7&quot;&gt; git fetch upstream -v&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-3 z-i&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;z-7&quot;&gt; git merge upstream/master&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you prefere you can create an alias in your &lt;em&gt;.gitconfig&lt;/em&gt;.&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;ini&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-4&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;z-10&quot;&gt;alias&lt;/span&gt;&lt;span class=&quot;z-4&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-3&quot;&gt;  pull_upstream&lt;/span&gt;&lt;span class=&quot;z-1&quot;&gt; =&lt;/span&gt;&lt;span&gt; !&lt;/span&gt;&lt;span class=&quot;z-7&quot;&gt;&amp;quot;git fetch origin -v; git fetch upstream -v; git merge upstream/master&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now &lt;em&gt;git pull_upstream&lt;/em&gt; will fetch the changes of both remotes, and the merge in the upstream changes.&lt;/p&gt;
</content>
        </entry>
</feed>
