14 Jun'13

Moving from Jekyll to Octopress

Hi again. Today I can proudly say that I was productively procrastinating! As you might know, my “Deep dive into Linux” journey has just began and today it saved me at least few hours.

While cleaning up my 1TB drive residing inside my desktop to make sure that all junk is removed whereas all important files are properly backed up to the cloud, I noticed that inside my old website folder there were at least 7 backup archives which were almost identical. They were consuming a lot of space and since going to the university I’ve being actively using git to keep my bacon safe ;) But that website was initially developed while I was back in school and knew nothing about VCS.

And I already had a repository containing the last backup as initial commit and a hadful of improvements. So I decided to create a new repository and progressively unpack backups in historical order. After I finished, I got the following commit history:

* a662b50 2013-06-14 '2011-11-30 CHANGES'
* 4849770 2013-06-14 '2011-11-30 gitignore update'
* 651073d 2013-06-14 '2011-11-30 REMOVE log file'
* 020d015 2011-09-19 '2011-09-19 REMOVED'
* b266571 2011-09-19 '2011-09-19 ADDED'
* 240cda1 2011-09-19 '2011-09-19 UPDATE GITIGNORE'
* 12d0ff6 2011-09-19 '2011-09-19 CHANGED'
* c6aff9f 2011-08-23 '2011-08-23 ADDED'
* e8f3ca3 2011-08-23 '2011-08-23 change DB name'
* 5815657 2011-08-23 '2011-08-23 Add wr-counter'
* b852e21 2011-08-23 '2011-08-23 Add IO-82 photo session album'
* 888c1af 2011-08-23 '2011-08-23 Add softtime poll'
* 6d93120 2011-08-23 '2011-08-23 Add poll'
* e126ebd 2011-08-23 'Remove DB files'
* 3a5e42d 2011-04-25 '2011-04-25 CHANGED'
* 3ea7973 2011-03-08 '2011-03-08 ADDED/REMOVED'
* 7b83c77 2011-03-08 '2011-03-08 CHANGED'
* 7f25721 2011-03-08 'Ignore cache files'
* c32668f 2011-01-08 '2011-01-21 NEW FILES'
* 4078adc 2011-01-08 '2011-01-21 CHANGES'
* 7a974c1 2010-01-17 '2010-01-17'
* 70bf95b 2010-01-17 'Add gitignore file'

Well, wait. Here comes a little bit of magic. How I managed to make commits with correct dates? In short, I forgot. So I had to find a solution afterwards, which turned out to be simple, but took some time to apply correctly:

git filter-branch -f --env-filter \
    'if [ $GIT_COMMIT = 651073d077e66282f1bd19ad55111ba5e07fad10 ]
     then
         export    GIT_AUTHOR_DATE="2011-11-30T15:40:00"
         export GIT_COMMITTER_DATE="2011-11-30T15:40:00"
     fi
     if [ $GIT_COMMIT = 48497704ac731d337c7fd48c4f6139abd9972af9 ]
     then
         export    GIT_AUTHOR_DATE="2011-11-30T15:41:00"
         export GIT_COMMITTER_DATE="2011-11-30T15:41:00"
     fi
     if [ $GIT_COMMIT = a662b50db73872d8cb14602eb6b7f7288b778fc6 ]
     then
         export    GIT_AUTHOR_DATE="2011-11-30T15:42:00"
         export GIT_COMMITTER_DATE="2011-11-30T15:42:00"
     fi'

Apply this code with care and note that -f switch must go directly after filter-branch. Hope this will save you a lot of time.

After that I began searching the internet for a repository concatenating solution. Task: there are two folders with a git repository in each and identical folder stucture;commit tree is almost flat; need to merge two repositories into one and preserve commit history (both).

What I stumbled across was a Git-FastExport CPAN module and a script git-stitch-repo. Before proceeding, I installed cpanminus:

sudo apt-get install liblocal-lib-perl
sudo apt-get install cpanminus
cpanm Git::FastExport::Stitch

I fetched working repository into folder smartfon and backup repository into folder smartfon-archive. I also created folder smarfon-result and initialized empty git repository there.

Then I ran the following command from smarfon-result:

git-stitch-repo ../smartfon-archive ../smartfon | /usr/lib/git-core/git-fast-import 

Then a saw the following commit tree:

* 6206703 2013-05-21 'fix xmlns'
* c5b065e 2013-05-21 'add self-link'
* a0926da 2013-05-21 'Fix the rss link'
...
* f693806 2013-05-18 'remove unused external scripts'
* 2b2bece 2013-05-18 'Initial commit'
* 020d015 2011-09-19 '2011-09-19 REMOVED'
* b266571 2011-09-19 '2011-09-19 ADDED'
* 240cda1 2011-09-19 '2011-09-19 UPDATE GITIGNORE'
* 12d0ff6 2011-09-19 '2011-09-19 CHANGED'
* c6aff9f 2011-08-23 '2011-08-23 ADDED'
* e8f3ca3 2011-08-23 '2011-08-23 change DB name'
* 5815657 2011-08-23 '2011-08-23 Add wr-counter'
* b852e21 2011-08-23 '2011-08-23 Add IO-82 photo session album'
* 888c1af 2011-08-23 '2011-08-23 Add softtime poll'
* 6d93120 2011-08-23 '2011-08-23 Add poll'
* e126ebd 2011-08-23 'Remove DB files'
* 3a5e42d 2011-04-25 '2011-04-25 CHANGED'
* 3ea7973 2011-03-08 '2011-03-08 ADDED/REMOVED'
* 7b83c77 2011-03-08 '2011-03-08 CHANGED'
* 7f25721 2011-03-08 'Ignore cache files'
* c32668f 2011-01-08 '2011-01-21 NEW FILES'
* 4078adc 2011-01-08 '2011-01-21 CHANGES'
* 7a974c1 2010-01-17 '2010-01-17'
* 70bf95b 2010-01-17 'Add gitignore file'

Comments