The McGyver GIT Survival Guide

Working with version control system is one of the elementary skills for each and every software engineer. Over the years, I worked with CVS, Subversion, SourceSafe, Perforce as well as Mercurial. Within Microsoft, I worked a lot with Source Deport and Microsoft Team Foundation Server. At home I run my dedicated SVN repository. In fact, I don’t feel comfortable when not being able to check in source code at all.

For my personal projects, Git especially Github works quite well, however, since the openHAB project moved from Google Code (Mercurial) to GitHub, I deal with quite a lot of issues within Git over and over. Currently we have more than 50 60 forks and more than frequent pull requests. Therefore, keeping your local branch permanently in sync is quite inevitable.

Abstraction None
The worst thing about Git is the fact, the user interface and console commands seem to reflect the Git implementation bit by bit. Personally, I have the feeling there is zero abstraction for the user. Even worse, when used to non distributed systems like SVN or TFS doing simple syncs and commits, the concepts behind Git might drive one mad.

Small Steps
This seems obvious, however, try to make only small commits to the repository. The more collaborators you have, the more challenging it might become to merge. At the same time, the less experienced you are with Git, the smaller your checkins should be. Commit single files, minor changes as isolated as possible. This will make you life just so much easier.

Daily Routine Conflicts
As daily routine, fetching and merging the local branch should be done via

git fetch upstream
git merge upstream/master

Usually, this should work quite well unless there are changes on local files that should not be merged at all or you have done changes not to be merged yet.

Updating e21a751..349468b
error: Your local changes to the following files would be overwritten by merge:
        foo/bar/buzz.ext
Please, commit your changes or stash them before you can merge.
Aborting

To just avoid the merge stash the changes via

git stash

Do the merge, and than pull the stash.

git stash pop

Again, usually this should work fine unless the merge results in a conflict which cannot be resolved automatically.

Auto-merging foo/bar/buzz.ext
CONFLICT (content): Merge conflict in foo/bar/buzz.ext

Simply run

git mergetool

to solve the issues and try to pull the stash again.

Delete from Repository only
To remove a file from the repository whilst keeping it locally just performa a

git rm --cached myfile.c

Bear in kind, this git will realise this file immediately as a new. rm works on folders as well, though. Anyway, this will become very handy once you accidentally check in files that are not intended to be checked in.

Backup early – Backup often
Just in case you don’t know what’s going to happen e.g. due to a larger refactoring – move the current state into a new brach as backup right after a commit

git branch my-backup-work

Reset to Remote
Ok, this one gave me quite a hard time, as I had changes checked in my forks but needed to reset particular files to the current revision of the original repository (not your local branch and neither your fork).

To do so, reset your working copy to the upstream master:

git remote update
git reset --hard upstream/master

Afterwards push this new branch-head to your origin repository, ignoring the fact that it won’t be a fast-forward:

git push origin +master

you might have something like

Fetching origin
Fetching upstream
remote: Counting objects: 685, done.
remote: Compressing objects: 100% (336/336), done.
remote: Total 507 (delta 249), reused 321 (delta 87)
Receiving objects: 100% (507/507), 6.57 MiB | 146.00 KiB/s, done.
Resolving deltas: 100% (249/249), completed with 64 local objects.
From https://github.com/aheil/example
   f55f8b0..e060456  master     -> upstream/master
macbook-pro:example andreas$

Reverting to a specific Revision
This one is easy, you simply need to tell git the hash of the revision you want to check out. This works quite well, however, you always need to consider the visibility of the branch you want to check out. To understand the reachability in git, you might want to read this article.

git checkout e095 -- somefolder/somefile

Conclusion
In my very personal opinion, Git is s**t if you are used to centralised repositories. If you worked a lot with Mercurial, Git is simply to complex. Git is not abstract enough. When working on code, I want spend 99% on the code and 1% on the revisioning system, not the other way around. When working on the open source projects, I currently waste a major part of my time on Git.

I probably will never setup and run a personal git server (I do run a SVN server and did run CVS before) and I probably will not maintain any Git servers (I did at work maintain Microsoft TFS, SVN and CVS servers, though).

Git is great when it comes to some kind of mass collaboration (but I haven’t found anything so far Mercurial won’t offer for the same purpose). While everybody plays nicely together, it works just great.

As there is much more to learn about Git, you eventually want to pick Pro Git to get some insights.

Where is my Space

Using Bootcamp, running a Mac OS X and a Windows installation in parallel, space is slowly but constantly running low on my MacBook Pro. Before upgrading my HDD, I was looking for a better way than using du or df -h to check where I might free up some space on my disk.

Disk Inventory X is a free tool available using cushion tree maps to visualise the disk usage. A similar tool was developed at the Technical University of Eindhoven named SequoiaView. While SequiaView was developed for Windows, Disk Inventory X is designed for Mac OS, working fine with version 10.8.3.

Disk Invetory X

After selecting the disk, it’s possible to browse through the directory structure analysing where your storage when to.

Disk Invetory X Cushion Tree

Both, SequoiaView for Windows and Disk Inventory X for Mac are quite useful programs that should be definitely part of ones toolset.

Ditto Clipboard Manager

One of the most annoying limitations using any version of Windows, is the clipboard and its limited capacity of one entry. Even Microsoft’s DOS supported sort of a clipboard striking the F7 key to choose from the last ten commands.

Command Prompt Clipboard

However, using Windows only one single item can be placed into the clipboard. Using multiple tools, documents over time one would speed up work significantly if it would be possible to keep many things in the clipboard at once.

Quite a while ago, Microsoft introduced the Clipboard Ring for Visual Studio to cycle through the most recent copied code snippets as especially developers often need different fragments of code over and over again (said that kids, please remember, copied code is never good at all).

Anyway, how great would be the experience using Windows if one could access such a clipboard ring or similar outside of Visual Studio? Ditto Clipboard Manager is a small open source project, providing especially this functionality:

“Ditto is an extension to the standard windows clipboard. It saves each item placed on the clipboard allowing you access to any of those items at a later time. Ditto allows you to save any type of information that can be put on the clipboard, text, images, html, custom formats, …..”

It does keep anything in your clipboard, is easy accessible and does even provide a preview for many things copied during your work day.

Ditto

There is a whole bunch of shortcuts and  if you don’t like its appearance go ahead and theme it differently. I haven’t tried all the options Ditto does provide, however, I am already using it on all my machines at work as well as home. So go and give it a try.

Pixeur Color Picker

For quite a time, Pixeur became one of the tools I almost can’t work without anymore. It is a lightweight and free color picker provided by Veign.

First of all, it’s easy to pick a color from the standard color palette. A great feature is the automated calculation of HSB, RGB and CMYK and Hex (the numbers used in HTML code) values. Which value you ever need, Pixeur does calculate the corresponding color codes. 

Pixeur Color Picker 

The ultimate uber feature is the screen picker tool. You simply drag and drop the pointer to the pixel on your screen you want to know the color code from.

Screen Color Picker

Drag and drop the target icon to whatever pixel on your screen to get the exact color value. In addition a zoomed area of the hovered are is shown in the corner of your screen which makes it quite easy to pin down a single pixel even on some kind of retina like displays.

Picking a single pixel with Pixeur

It’s very simple to use and so far I haven’t had any issues with the tool. Amazingly, the tool worked since ever on various Windows versions I used so far including Vista and windows 7 without the need of updating.

Pro:

  • easy to use
  • low footprint (~2MB)
  • provides color values in various formats
  • screen wide color picker
  • zoom of the hovered area when picking a color
  • free (i.e. no money, cash, PayPal or diamonds needed)

Contra:

  • Hard to find on the web

The tool is so great, I usually forget about it until I need to get a color code or pick some pixel’s color from the screen. It’s one of the first tools I install after setting up a new machine, and there’s the problem – if you don’t know where to find it, it’s hell of a job to find the download site.

There are probably a dozen of similar tools out in the wild, and each and every major drawing program probably provides such features. However, as a free, and very easy to use alternative, give it a try.

Restore Desktop Layout on Windows

Works on my machine!I continually move between different office places using different setups for monitors with my laptop. Sizes, numbers and orders of the monitors vary from place to place. As a consequence, you either deal with a complete mess on your desktop or you spend several hours per week in rearranging icons on your desktop.

Tired of doing so, I was looking for a nice tool for Windows, easy to use. Desktop Restore by Jamie O’Connell is such a tool available for Windows x86 and x64 systems and it is free to use (while he appreciate donations). For me, it works fine on a Windows 7 64-bit machine.

It integrates well with the Windows Explorer  context menu where you can save and restore layouts for different resolutions. This even allows you to set up your desktop for different locations and restore them with a single mouse click.

Desktop Restore

I have used it for ages, however, I have not really realized how great this tools until I set up my machine from the scratch recently. 

Windows Metafile Preview on Windows 7

Works on my machine!The visual preview of files in Windows Explorer is one of the great features of Windows when looking for a certain file. Unfortunately, with Windows Vista Microsoft disabled the preview for Windows Metafile Format (.WMF) and Enhanced Metafile Format (.EMF) files. As I needed t work a lot with EMF files during my latest book project with Springer, I was looking for some way to enable the preview of the file types mentioned above in Windows Explorer.

Windows 7 without EMF/WMF preview

Fortunately, there is a great plugin called emfplugin written by Daniel Gehringer to enable the preview. The plugin is available for x32 and x64 machines and should work on both, Windows Vista and Windows 7. Once installed (and rebooted) the Windows Explorer is capable of displaying EMF and WMF files.

Windows Explorer EMF and WMF thumbnail preview plug-in

The plugin is licensed under the MIT license, so its safe to go with it. At the very end this raises the question why Microsoft did actually disable the preview for two formats developed by Microsoft itself and whether they might work with Windows 8 again.

DropBox with TrueCrypt on Lion and Windows

After receiving my new MacBook, I wanted to sync a whole set of files between both systems. For convenience, I decided to use DropBox instead of a thumb drive and for security reasons, I decided to use TrueCrypt to encrypt some of my confidential data within the DropBox folders.

Using a TrueCrypt container within DropBox is quite convenient as I am syncing my DropBox folders with various machines (e.g. at work). However, I do not want to access these file there nor do I want that an admin might check out my “oooh so secret” files (not saying they would, though).

DroppBox with TrueCrypt on Lion and Windows

With my rusty Mac OS kung-fu, I had to install TrueCrypt first. Of course, this failed and being the first app I did install on Lion, this was somewhat demotivating. Before you have install a version from MACFuse. It seems that the official version is not up to date, however, there are rumors you might use the latest version provided at Tuxera.com.

Once MACFuse and TrueCrypt are set up and the machine is rebooted, create a TrueCrypt container within DropBox. When creating on OS X Lion, you might want choose FAT for the containers file system so you can mount it on the Windows system as well. However, any change within this container will synchronize the container as a whole. Not being very efficient if this is a 256 MB file, it seems that one can turn of the timestamp of the TrueCrypt container to avoid syncing it. This will prevent that the container gets synced after files within the container are changes, however, the itself files are still updated. To turn it of, open TrueCrypt and select Settings / Preferences… chose the Security tab and uncheck the Preserve modifications timestamp of file container checkbox.

TrueCrypt Settings on OS X Lion

Of course, the same has to be done on your Windows system.

TrueCrypt Settings on Windows 7

Once both settings are applied, only the initial sync of the container will take some time. Thereafter, only the files within the container are updated. for me this seems to be a quite good solution to keep my boxes in sync and to avoid rubbernecks seeking through my private stuff. The setup is done quite easily, only the hassle with MACFuse was quite annoying.

Cleaning Up the Explorer ‘New’ Menu

If you are using your Windows machine for a while, it is inevitable that you install a whole bunch of Software. Especially a developer machine might end up with a lot of application and tools, you use for work or evaluation. This is the first article in a series of steps how to clean up your Windows machine, and to optimize your personal workflow.

Some tool that come with support for a particular file extension might extend the Windows Explorer ‘New’ sub menu. In my case I currently ended up with about 20 entries, while I regularly use only two or three of them. Most if them I barely touch. To minimize noise and to speed up your personal workflow you might want to get rid of some of them and renaming others. E.g. all Office documents are usually prefixed with ‘Microsoft’ while you might just want to see them as ‘Word Document’  or ‘Excel Document’.

Insert New Menu

 

To modify these entries, you eventually would use the Registry Editor. Each entry is located in the registry using its own key at:

HKEY_CLASSES_ROOT.[fileExtension]ShellNew

However, maintaining this list is rather time-consuming task and no fun at all.  After some investigation I found a very nice freeware tool called ShellMenuNew from NirSoft that eventually does the job for you. It’ is a small tool which does not need to be installed and can be used straight away.

ShellMenuNew

By right-clicking any of the entries you can select ‘Disable Selected Menu Items’. Once you open up the ‘New’ submenu in Windows Explorer the menu should be look much tidier.

In case you change your mind, you can always start ShellMenuNew again and enable the file extensions again. The tool worked nicely on my x64 Windows 7. Regarding the author’s website it should also work on Windows 2000, Windows XP, Windows Server 2003/2008, and Windows Vista. Solved this task,  the renaming of the entries is still pending.

Modified Windows Explorer 'New' File Menu

Also here a small freeware tool comes in handy. Default Programs Editor provides a set of functionality to edit file type settings, autoplay settings and default programs settings. Also this tool can be sued straight away and does not need any installation.

Default Programs Editor

Default Programs Editor lets you easily change any kinds of associations with respect to files extension. Using the ‘File Type Settings’ you can select the ‘Description’, search for the file type you want to rename and finally change the file type description.

Using those two tools it is possible to minimize noise in your working environment without hacking the registry manually.

Quickstart with AWStats and IIS 7

AWStats is a free, Perl-based analyzer for log files. To get results quickly on a Windows Server 2008 with IIS 7 you only have to follow a few steps. These are not well documented in the AWStats documentation and require some time of research. This post will show you how to set up AWStats with IIS7 in only a few minutes.

  1. Install Perl, e.g. ActivePerl. There are 32-bit and 64-bit versions available. Make sure that Perl is added to your PATH environmental variable. The ActivePerl installer usually provides this option during the installation.
  2. Install AWStats. Remember the path AWStats is installed. Paths used below are based on the installation folder of AWStats. In this example we use c:awstats.
  3. Run the configuration script at c:\awstatstoolsawstats_configration.pl. Follow the on screen instructions. This will create a default configuration file in c:\awstatswwwrootcgi-bin e.g. called awstats.www.example.org.config. The site name www.example.org depends on whatever site name was provided while running the script. When asked for the Apache Web server path type in none.AWStats Configuration File
  4. Open the configuration file awstats.www.example.org.config with any text editor of your choice.
  5. AWStats already supports IIS, however, it is required to tweak the config file. First change the entry for LogFile. Log files for IIS might be found at c:inetpublogsLogFilesW3SVCNNN where NNN is a different number for each web site, IIS creates log files for. Change the entry toLogFile=”c:awstatstoolslogresolvemerge.pl c:inetpublogsLogFilesW3SVC1*.log |”

    This will merge all log files for a site provided by IIS. Adjust the paths corresponding to your installations and desired log file folders.

  6. The AWStats configuration file offers the possibility to set the LogFormat to IIS (LogFormat=2), however, the log entries provided by a standard installation of IIS 7 won’t match. The AWStats documentation recommends to change the settings of IIS. The change will take effect only after restarting the Web site and is only valid for entries after that particular moment. Consequently, this is not an option if you are going to analyze the logs of the last 12 months where the original settings were used. To make AWStats work with the standard log format of IIS 7 change the LogFormattoLogFormat=”%time2 %other %method %url %other %query %other %host %other %code % %other %other %bytesd”
  7. Change SiteDomain and HostAliases to meet the settings of your site.
  8. Change to c:awstatswwwrootcgi-binand runawstats.pl -config=www.example.org

    This will build the statistics database for AWStats.

  9. To create output runawstats.pl -config=www.example.org –output –staticlinks > …example_org_stats.html
  10. Not that example_org_stats.html is created one folder up. In case you do miss this, the output will not work correctly until you adapt the entries for DirCgi and DirIcons in the configuration file.
  11. The output file is now located in c:awstatswwwroot. You might want to create a Virtual Directory or set up a Web site to view the reports via the Web or your Intranet.AWStats Output

Repeat steps 3-7 fore each site you want to create reports for. Repeat step 8 and 9 every time you want to create a new report.

f.lux Compensator

Not really a productivity tool, but apparently some tool that makes working all day long on the screen much more convenient.

“f.lux makes your computer screen look like the room you’re in, all the time. When the sun sets, it makes your computer look like your indoor lights. In the morning, it makes things look like sunlight again”

f.lux adjusts the color temperature of your display to the time of the day. It ranges from 6500 Kelvin during daylight to 3400 Kelvin during the night. Give it a try, downloads are available for Windows XP/Vista, Mac OS X and Linux (glibc6).

f.lux